Description
Defines an interface for creating an object, but let subclasses decide which class to instantiate. It defers instantiation to subclasses.
Where to use
- Library frameworks. \n
- When exact types aren't known ahead of time.
Real World Example
A 'Logistics' class handles delivery. 'RoadLogistics' creates a 'Truck', 'SeaLogistics' creates a 'Ship'. The client just calls 'createTransport()'.
Code Example
class FactoryMethod:
def __init__(self):
pass
def execute(self):
print('Executing Factory Method')
