MCPcopy Create free account
hub / github.com/RefactoringGuru/design-patterns-python / Invoker

Class Invoker

src/Command/Conceptual/main.py:101–143  ·  view source on GitHub ↗

EN: The Invoker is associated with one or several commands. It sends a request to the command. RU: Отправитель связан с одной или несколькими командами. Он отправляет запрос команде.

Source from the content-addressed store, hash-verified

99
100
101class Invoker:
102 """
103 EN: The Invoker is associated with one or several commands. It sends a
104 request to the command.
105
106 RU: Отправитель связан с одной или несколькими командами. Он отправляет
107 запрос команде.
108 """
109
110 _on_start = None
111 _on_finish = None
112
113 """
114 EN: Initialize commands.
115
116 RU: Инициализация команд.
117 """
118
119 def set_on_start(self, command: Command):
120 self._on_start = command
121
122 def set_on_finish(self, command: Command):
123 self._on_finish = command
124
125 def do_something_important(self) -> None:
126 """
127 EN: The Invoker does not depend on concrete command or receiver classes.
128 The Invoker passes a request to a receiver indirectly, by executing a
129 command.
130
131 RU: Отправитель не зависит от классов конкретных команд и получателей.
132 Отправитель передаёт запрос получателю косвенно, выполняя команду.
133 """
134
135 print("Invoker: Does anybody want something done before I begin?")
136 if isinstance(self._on_start, Command):
137 self._on_start.execute()
138
139 print("Invoker: ...doing something really important...")
140
141 print("Invoker: Does anybody want something done after I finish?")
142 if isinstance(self._on_finish, Command):
143 self._on_finish.execute()
144
145
146if __name__ == "__main__":

Callers 1

main.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected