design-patterns/creational/factory-method/creators.py
Ruidy 7b0e4a5801
Singleton (#6)
* singleton example

* chore: enforce style guidelines
2020-09-14 21:27:39 +02:00

25 lines
713 B
Python

"""
Concrete Creators override the factory method in order to change the resulting
product's type.
"""
from __future__ import annotations
from ICreator import ICreator
from 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()