The Factory Method describes how to solve the recurring problem to design flexible, reusable, object-oriented software.
We need objects, created at runtime, that are easier to implement, change, test, and reuse.
Create different characters in our game
- Define an interface for creating an object, but let subclasses decide which class to instantiate
- It lets a class defer instantiation to subclasses
- Class can't expect the type of object it must create
- Subclass must decide what types of objects are create
- Delegate object creation
- Hook for subclasses
- Base class can provide a default implementation
- Delegate object creation at runtime
- When we don't know what type of class we need to create