Factory
- defines an interface for creating an object, but allows subclasses to alter the type of objects that will be created
pros
- Single Responsibility Principle (SRP)
- object creation code is isolated in one place, making the code easier to support
- Open/Closed Principle (OCP)
- you can introduce new variants of products without breaking existing client code
cons
- code may become more complicated than it should be since a lot of new subclasses are introduced along with the pattern
usages
- when you don’t know beforehand the exact types and dependencies of the objects your code should work with
- when you want to provide users of your library or framework with a way to extend its internal components
relations
- Iterator - Factory
- to let collection subclasses return different types of iterators that are compatible with the collections
- Template - Factory
- Factory is a specialization of Template
- at the same time, a Factory may serve as a step in a large Template
Abstract Factory
- provides an interface for creating families of related or dependent objects without specifying their concrete classes
pros
- Single Responsibility Principle (SRP)
- object creation code is isolated in one place, making the code easier to support
- Open/Closed Principle (OCP)
- you can introduce new variants of products without breaking existing client code
cons