Command Design Pattern - Is Invoker Optional?

后端 未结 2 976
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-14 07:19

Is Invoker class optional in Command design pattern? Client needs to instantiate Concrete Command and Receiver for the command. Does client always need to instantiate Invoker an

2条回答
  •  梦谈多话
    2021-02-14 08:01

    As we know, java.lang.Runnable is one of the examples of command pattern where Thread class works as an invoker. We pass object of a Runnable class to Thread class and say start/run.

    But we never create a client class which can invoke main thread.

    So an invoker is not optional but it is not tightly coupled to client. So UML of command pattern never shows any relationship among client class and invoker class.

    Another answer related to this question.

提交回复
热议问题