Search code examples
command-patterndesign-patterns

Command Pattern: Client and Invoker


In the command pattern:

Why shouldn't the client participant be the same class as the invoker participant? Is there possible scenarios when the client participant and the invoker participant can be the same class?


Solution

  • Biggest reason is that it violates the single responsiblity principle. The Client participant and Invoker particpant both have individual responsibilties and a change to one will affect the other.