EN: However, some commands can delegate more complex operations to other objects, called "receivers." RU: Но есть и команды, которые делегируют более сложные операции другим объектам, называемым «получателями».
| 46 | |
| 47 | |
| 48 | class ComplexCommand(Command): |
| 49 | """ |
| 50 | EN: However, some commands can delegate more complex operations to other |
| 51 | objects, called "receivers." |
| 52 | |
| 53 | RU: Но есть и команды, которые делегируют более сложные операции другим |
| 54 | объектам, называемым «получателями». |
| 55 | """ |
| 56 | |
| 57 | def __init__(self, receiver: Receiver, a: str, b: str) -> None: |
| 58 | """ |
| 59 | EN: Complex commands can accept one or several receiver objects along |
| 60 | with any context data via the constructor. |
| 61 | |
| 62 | RU: Сложные команды могут принимать один или несколько |
| 63 | объектов-получателей вместе с любыми данными о контексте через |
| 64 | конструктор. |
| 65 | """ |
| 66 | |
| 67 | self._receiver = receiver |
| 68 | self._a = a |
| 69 | self._b = b |
| 70 | |
| 71 | def execute(self) -> None: |
| 72 | """ |
| 73 | EN: Commands can delegate to any methods of a receiver. |
| 74 | |
| 75 | RU: Команды могут делегировать выполнение любым методам получателя. |
| 76 | """ |
| 77 | |
| 78 | print("ComplexCommand: Complex stuff should be done by a receiver object", end="") |
| 79 | self._receiver.do_something(self._a) |
| 80 | self._receiver.do_something_else(self._b) |
| 81 | |
| 82 | |
| 83 | class Receiver: |