Command Design Pattern - Is Invoker Optional?

后端 未结 2 1294
心在旅途
心在旅途 2021-02-14 07:01

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 07:34

    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.

提交回复
热议问题