mirror of
https://github.com/rjNemo/design-patterns
synced 2026-06-06 02:26:40 +00:00
* doc: create package & update general TOCs * doc: add documentation * add code example * reformat using black
23 lines
729 B
Python
23 lines
729 B
Python
"""
|
|
Concrete Creators override the factory method in order to change the resulting
|
|
product's type.
|
|
"""
|
|
|
|
from creational.factory_method.ICreator import ICreator
|
|
from creational.factory_method.products import ConcreteProduct1, ConcreteProduct2
|
|
|
|
|
|
class ConcreteCreator1(ICreator):
|
|
"""
|
|
Note that the signature of the method still uses the abstract product type,
|
|
even though the concrete product is actually returned from the method. This
|
|
way the Creator can stay independent of concrete product classes.
|
|
"""
|
|
|
|
def factory_method(self) -> ConcreteProduct1:
|
|
return ConcreteProduct1()
|
|
|
|
|
|
class ConcreteCreator2(ICreator):
|
|
def factory_method(self) -> ConcreteProduct2:
|
|
return ConcreteProduct2()
|