Factory Method
The core idea is the use a method to create instances of a all related subclasses.
- All products (instances returned by the factory method) must use a common interface.
- The factory method should return the interface common to all subclasses.
- All code that constructs components should be confined to the factor method.
- The client code interacts with the base interface, which is overriden by each subclass depending on desired functionality.
- The factory pattern seperates the logic that interacts with your classes from the construction of the classes themselves. Thus, to add a new product type to your program, you only need to override the factory method.
ADDITIONAL RESOURCES Must read resource on Factory Method pattern (see How to Implement)