mirror of
https://github.com/rjNemo/design-patterns
synced 2026-06-06 02:26:40 +00:00
24 lines
705 B
Python
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())
|