- Abstraction
- Polymorphism
- Encapsulation
- Inheritance
- Dependency (dotted line, arrow) - some change to one might result in changes to another
- Association (solid line, arrow) - one object uses or interacts with another
- Aggregation (open diamond, solid line, arrow) - one-to-many, many-to-many, or whole-part relation
- Composistion (solid diamond, solid line, arrow) - specific aggregation one obj is composed with another
- S - Single Responsibility Principle
- O - Open/Closed - open for extension, closed for modification
- L - Liskov Substitution Principle
- I - Interface Segregation Principle
- D - Depenency Inversion Principle
- Provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that are created.
- Delegate object creation to a factory class
- Different objects related to a common interface
- Use Facotry Method when you don't know beforehand the exact types and dependencies of the objects your code should work with.
- Use the Factory Method when you want to provide users of your library or framework with a way to extend its internal components.
- Use the Factory Method when you want to save system resources by reusing existing objects instead of rebuilding them each time.
- make all products follow the same interface. This interface should eclare methods that make sense in every product.
- Add an empty factory method inside the creator class. The return type of the method should match the common product interface.
- Move object creation inside of the factory method, replacing the constructor call with the method call.
- Create set of creator subclasses for each type of product listed in the factory method, moving creation code
- (+) avoid tight coupling
- (+) single responsibility principle
- (+) open/closed principle
- (-) code complexity