Something about command pattern, Why do most of the examples call receiver directly but not invoker in main?

StackOverflow https://stackoverflow.com/questions/19742895

  •  03-07-2022
  •  | 
  •  

سؤال

Something about command pattern, Why do most of the examples call receiver directly but not invoker in client?

In most of the example on internet,(img : http://www.dofactory.com/Patterns/Diagrams/command.gif) ,why the client call the receiver to do action but not invoker? It seems like client call action via invoker or directly though command interface is better because the actual action coding is inside the receiver . If we change any path of action code, the changing on the code of receiver and client are necessary. If we use invoker to call the actual command, it will reduce the dependency.

Therefore, why should we still call the action via receiver in general example? Please help. Thank you.

هل كانت مفيدة؟

المحلول

I think you are reading a class diagram like it was a sequence diagram. The sequence diagram for most common examples of CommandPattern decribes how the client calls the action method through the Invoker as you expected.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top