Creational Patterns
createDocument()
in Application
). Concrete
subclasses override it to return specific products (e.g., SpreadsheetDocument
, TextDocument
). Clients call the factory
method on the base class interface, but the actual subclass controls the product’s type. This decouples product creation
from client code.
factory_method()
, and its subclasses (ConcreteCreator1
,
ConcreteCreator2
) override this method to create specific products (ConcreteProduct1
, ConcreteProduct2
). The
client code uses a creator without knowing the exact product class.
Pizza
” or a “Burger
”, and the restaurant has a method to decide how and who prepares it.
This “method” is the Factory Method
— it decides which concrete class (Chef) will make your product (food).