description |
---|
Design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created. |
Use the Factory Method when
📒 you don’t know beforehand the exact types and dependencies of the objects your code should work with.
📒 you want to save system resources by reusing existing objects instead of rebuilding them each time.
📒 you want to provide users of your library or framework with a way to extend its internal components.
🟢 You avoid tight coupling between the creator and the concrete products.
🟢 Single Responsibility Principle. You can move the product creation code into one place in the program, making the code easier to support.
🟢 Open/Closed Principle. You can introduce new types of products into the program without breaking the existing client code.
🔴 The code may become more complicated since you need to introduce a lot of new subclasses to implement the pattern. The best-case scenario is when you’re introducing the pattern into an existing hierarchy of creator classes.\
To be updated.
- https://refactoring.guru/design-patterns/factory-method
- https://www.youtube.com/watch?v=ub0DXaeV6hA&list=PLF206E906175C7E07&index=5
\