Often a static method
Decloupes clients from implementation details of derived classes
Enables poloymorphic creation.
Arguments to method determine what object should be created, factory determins how.
Unlike a constructor could return:
- Reused object
- More descriptive names
The factory method pattern is used to create objects. It is useful in that encapsulates object creation from clients.
Interface for product objects
This is a concrete implementation of IProduct.
ProductFactory is an abstract class that declares the factory method which returns an object of type IProduct
ProductFactoryConcrete implements the abstract ProductFactory. It overrides the factory method and returns concrete Products.