design-patterns/creational/factory_method/creators.py
2020-09-29 22:05:56 +02:00

24 lines
735 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()