Factory : Design Patterns In Python
https://medium.com/design-patterns-in-python/factory-pattern-in-python-2f7e1ca45d3e
Documentation : https://sbcode.net/python/factory/
When developing code, you may instantiate objects directly in methods or in classes. While this is quite normal, you may want to add an extra abstraction between the creation of the object and where it is used in your project.
You can use the Factory pattern to add that extra abstraction. The Factory pattern is one of the easiest patterns to understand and implement.
Adding an extra abstraction will also allow you to dynamically choose classes to instantiate based on some kind of logic.
Before the abstraction, your class or method would directly instantiate an object of a class. After adding the factory abstraction, the concrete product (object) is now created outside of the current class/method, and now in a subclass instead.
(Book)Sometimes you just want to switch off your computer and read from a book. So, this pattern, plus all other GoF patterns are discussed in my Design Patterns In Python book
https://www.amazon.com/dp/B08XLJ8Z2J : ASIN B08XLJ8Z2J
https://www.amazon.com/dp/B08Z282SBC : ASIN B08Z282SBC
#factory
#factoryPattern
#designPatterns
#pythonDesignPatterns