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

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

24 lines
705 B
Python

from creators import ConcreteCreator1, ConcreteCreator2
from ICreator import ICreator
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())