design-patterns/creational/factory_method/main.py
Ruidy c8cc1f47b8
Observer (#20)
* doc: create package & update general TOCs

* doc: add documentation

* add code example

* reformat using black
2020-10-06 08:25:18 +02:00

24 lines
757 B
Python

from creational.factory_method.ICreator import ICreator
from creational.factory_method.creators import ConcreteCreator1, ConcreteCreator2
def client_code(creator: ICreator) -> None:
"""
The client code works with an instance of a concrete creator, albeit
through its base interface. As long as the client keeps working with the
creator via the base interface, you can pass it any creator's subclass.
"""
print(
f"Client: I'm not aware of the creator's class, but it still works.\n"
f"{creator.some_operation()}",
end="",
)
print("App: Launched with the ConcreteCreator1.")
client_code(ConcreteCreator1())
print("\n")
print("App: Launched with the ConcreteCreator2.")
client_code(ConcreteCreator2())