design-patterns/structural/facade/main.py
Ruidy 834f1ded23
add facade code example (#11)
Co-authored-by: Ruidy <r.nemausat@empfohlen.de>
2020-09-27 14:31:15 +02:00

24 lines
883 B
Python

from structural.facade.facade import Facade
from structural.facade.subsystems import Subsystem1, Subsystem2
def client_code(facade: Facade) -> None:
"""
The client code works with complex subsystems through a simple interface
provided by the Facade. When a facade manages the lifecycle of the
subsystem, the client might not even know about the existence of the
subsystem. This approach lets you keep the complexity under control.
"""
print(facade.operation(), end='')
if __name__ == '__main__':
# The client code may have some of the subsystem's objects already created.
# In this case, it might be worthwhile to initialize the Facade with these
# objects instead of letting the Facade create new instances.
subsystem1 = Subsystem1()
subsystem2 = Subsystem2()
facade = Facade(subsystem1, subsystem2)
client_code(facade)