The Factory Pattern in Python // Separate Creation From Use
205K views · Jul 16, 2021 · Education
Comments · 265
@ArjanCodes · 2 years ago · pinned
💡 Here's my FREE 7-step guide to help you consistently design great software: <a href="https://arjancodes.com/designguide">https://arjancodes.com/designguide</a>.
1
@johnstanley1993 · 5 years ago
For me as a data scientist your videos really stepped up my software development game. The Factor Pattern together with having abstract classes as interfaces is something I immediately applied in my current project. This is not something you typically learn in data science courses, even though I think this is crucial when willing to write code in a professional context. Thanks Arjan for sharing those valuable insights!
103
@yaczesuaff · 5 years ago
I'm binging your videos currently and (among other things) there's something I love: the examples are meaningful. They are practical, solve actual problems. Not your another off the mill tutorial with generic class C inheriting class B etc. Seeing that your example applications mimic actually doing something, makes it 100x easier to wrap the application logic and focus on the topic at hand. I'm amazed.
16
@VCR47527 · 4 years ago
Unsure if this is mentioned somewhere, but this is the GOF Abstract Factory pattern. Not to be confused with the GOF Factory Method pattern. The Abstract Factory pattern's goal is, as Arjan says, for grouping different class instantiations together. The Factory Method pattern is about extending the functionality of a class.
57
@002uzumaki · 5 years ago
I just found out about you today while learning certain design patterns. Now, I started reading about factory patterns just a few hours ago and boom, you're here with the video. Thanks for the video. Maybe adapter pattern in the next video?
45
@richarddanipog4975 · 1 year ago
Finally, a video that explains the factory pattern well and clearly. Thank you very much I so enjoy your presentation and delivery!
1
@AsenovMiroslav · 3 years ago
I would like to propose the use of a factory dictionary approach, where the dictionary values store class names instead of actual instances. This can be more efficient, especially when creating instances is resource-intensive. The idea is to define a dictionary of factories like this:<br><br>factories = {<br> 'one': FactoryOne,<br> 'two': FactoryTwo<br>}<br><br><br>Later, when you need to create an instance based on a specific key, you can use the stored class names to instantiate the desired objects. This is done as follows:<br>return factories[key]()<br><br>With this approach, you optimize memory usage by storing class names, and actual instances are only created when needed.
4
@ytlagu2010 · 4 years ago
I really like the idea where you first present the problem and show the solution. Most videos I watched rant about the theory but forgets to tell you the why part.
@cabanford · 5 years ago
I so enjoy your presentation and delivery. Great job in explaining "why" things are used and not just the typical "how" (which is what geeks who already grokk something tend to do). <br><br>I also like how you discuss what things a pattern doesn't do well and then you provide an alternative for such cases. ⭐⭐⭐
9
@JonMartins · 5 years ago
I'm addicted to your channel man!<br>Congrats. Cheers from Brazil.
@9boss6 · 5 years ago
Thank you for what you are doing. It is really helpful. Keep going.
4
@mdunkman · 5 years ago
I really enjoyed the video. Your pacing and amount of content is very good as a reference!<br><br>In a future video, could you clarify the differences between a Factory Pattern and a Builder Pattern? I feel like the builder is a way to collect factories, but I would enjoy seeing a worked example.
8
Up next

The Factory Design Pattern is Obsolete in Python
ArjanCodes · 116K views

Uncle Bob’s SOLID Principles Made Easy 🍀 - In Python!
ArjanCodes · 357K views

Don’t Use Boolean Flags in Python, Use Policies Instead
ArjanCodes · 165K views

What does '__init__.py' do in Python?
Tech With Tim · 357K views

Python Design Patterns Tutorial for Beginners 2022
miss google · 15K views

Factory Method Pattern in Python: Creating Objects with Ease
campbelltech · 5.7K views

QUESTIONABLE Object Creation Patterns in Python 🤔
ArjanCodes · 77K views

! Python design patterns masterclass
CodeTekTeach · 34K views

Let's Take The Adapter Design Pattern To The Next Level
ArjanCodes · 56K views

High-performance Database Architecture - An Interview with Tyler Cloutier
Molly Rocket · 124K views

How to Implement the Strategy Design Pattern in Python
ArjanCodes · 59K views

Factory Method Pattern – Design Patterns (ep 4)
Christopher Okhravi · 613K views

How To Reduce Coupling With Facade | Design Pattern Tutorial
ArjanCodes · 48K views

The Builder Pattern in Python: Finally Explained!
ArjanCodes · 65K views

MCP vs API Explained: Do You Really Need MCP?
KodeKloud · 238K views

HashMaps in Python Tutorial - Data Structures for Coding Interviews
Codebagel · 309K views

Music for Work — Deep Focus Mix for Programming, Coding
Chill Flow · 2.4M views

7 Design Patterns EVERY Developer Should Know
ForrestKnight · 1.3M views

How to use the STRATEGY PATTERN in Python
Coders Bring Change · 5.4K views

Pydantic Tutorial • Solving Python's Biggest Problem
pixegami · 514K views

Learn MCP Servers with Python (EASY)
Alejandro AO · 148K views

Two UNDERRATED Design Patterns 💡 Write BETTER PYTHON CODE Part 6
ArjanCodes · 74K views

Solving A Common Issue With The Strategy Pattern // In Python
ArjanCodes · 52K views

10 Important Python Concepts In 20 Minutes
Indently · 1.6M views

Python Tutorial: Working with JSON Data using the json Module
Corey Schafer · 1.3M views