EN: The Facade class provides a simple interface to the complex logic of one or several subsystems. The Facade delegates the client requests to the appropriate objects within the subsystem. The Facade is also responsible for managing their lifecycle. All of this shields the client f
| 15 | |
| 16 | |
| 17 | class Facade: |
| 18 | """ |
| 19 | EN: The Facade class provides a simple interface to the complex logic of one |
| 20 | or several subsystems. The Facade delegates the client requests to the |
| 21 | appropriate objects within the subsystem. The Facade is also responsible for |
| 22 | managing their lifecycle. All of this shields the client from the undesired |
| 23 | complexity of the subsystem. |
| 24 | |
| 25 | RU: Класс Фасада предоставляет простой интерфейс для сложной логики одной |
| 26 | или нескольких подсистем. Фасад делегирует запросы клиентов соответствующим |
| 27 | объектам внутри подсистемы. Фасад также отвечает за управление их жизненным |
| 28 | циклом. Все это защищает клиента от нежелательной сложности подсистемы. |
| 29 | """ |
| 30 | |
| 31 | def __init__(self, subsystem1: Subsystem1, subsystem2: Subsystem2) -> None: |
| 32 | """ |
| 33 | EN: Depending on your application's needs, you can provide the Facade |
| 34 | with existing subsystem objects or force the Facade to create them on |
| 35 | its own. |
| 36 | |
| 37 | RU: В зависимости от потребностей вашего приложения вы можете |
| 38 | предоставить Фасаду существующие объекты подсистемы или заставить Фасад |
| 39 | создать их самостоятельно. |
| 40 | """ |
| 41 | |
| 42 | self._subsystem1 = subsystem1 or Subsystem1() |
| 43 | self._subsystem2 = subsystem2 or Subsystem2() |
| 44 | |
| 45 | def operation(self) -> str: |
| 46 | """ |
| 47 | EN: The Facade's methods are convenient shortcuts to the sophisticated |
| 48 | functionality of the subsystems. However, clients get only to a fraction |
| 49 | of a subsystem's capabilities. |
| 50 | |
| 51 | RU: Методы Фасада удобны для быстрого доступа к сложной функциональности |
| 52 | подсистем. Однако клиенты получают только часть возможностей подсистемы. |
| 53 | """ |
| 54 | |
| 55 | results = [] |
| 56 | results.append("Facade initializes subsystems:") |
| 57 | results.append(self._subsystem1.operation1()) |
| 58 | results.append(self._subsystem2.operation1()) |
| 59 | results.append("Facade orders subsystems to perform the action:") |
| 60 | results.append(self._subsystem1.operation_n()) |
| 61 | results.append(self._subsystem2.operation_z()) |
| 62 | return "\n".join(results) |
| 63 | |
| 64 | |
| 65 | class Subsystem1: |