N
N
NikolayAlb2017-03-15 22:09:56
Design patterns
NikolayAlb, 2017-03-15 22:09:56

What is the role of 'Invoker' in the Command pattern?

I can't figure out this pattern.
59802adeac5d40f08e893b8353cd593e.gif
What I understand:
Receiver is a class that stores the implementations of our commands.
ConcreteCommand - a class that characterizes a command as an object, essentially redirects us to the appropriate implementation in the Receiver.
What is the role of the Invoker class?
As I understand it in a simple execution: it should have a method to which we pass the command as an argument, and it already calls execute () of the command. And we create/configure the command itself in the client.
Then the question arises - why is it actually needed, if we can call execute in the client.
I would be grateful for clarifications.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-03-16
@NikolayAlb

Receiver - Contains a set of certain functionality
Command - Contains an algorithm for implementing a specific action using the functionality inherent in the Receiver
Client - Knows how to create a command and which Receiver to slip it
Invoker - Executes a specific command
Firstly, it does not always happen that the command is called where it is created. Secondly, Invoker contains mechanisms for executing all commands, i.e. for example, it can contain the formatting of the result of the execution of commands and other actions related to the execution of ALL application commands.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question