- Singleton Pattern
- Builder Pattern
- ProtoType Pattern
- Factory Method pattern
- Abstract Factory Pattern
- AVoids costly creation
- Avoids subclassing
- Typically doesn't use new
- Often utilizes an Interface
- Usually implemented with a Registry
- Example:
- java.lang.Object#clone()
- Sometimes not clear when to use
- Used with other patterns
- SHallow copy only
- Doesn't expose instantiation logic
- Defer to subclass
- Common interface
- Specified by architecture, implemented by user
- Example:
- Calendar
- ResourceBundle
- NumberFormat
Factory is responsible for lifecycle
Common Interface
Concrete Classes
Parameterized create method
- Complexity, need to write a lot of code
- Refactoring is not possible
- Factory of Factories
- Factory of related objects
- Common interface
- Defer to subclass
- Example:
- DocumentBuilder
Group Factories together
Factory is responsible for lifecycle
Common Interface
Concrete Classes
Parameterized create method
Build using composition
- Complexity, need to write a lot of code
- Refactoring is not possible