An example class diagram

When talking about the command design pattern, there are usually a couple of objects, each of which has its specific role:

  • Command: We can think of this as the interface and its implementations that are being called by the invoker.
  • Receiver: This is the object that actually knows how commands are executed. Think of this as an object that is being passed to the command and then used in the interface method.
  • Invoker: It invokes the commands by calling their interface method. As we mentioned earlier, it might not even know what commands are being invoked.
  • Client: It more or less guides which commands are executed when by using the invoker.

Now that we know the most important objects and their roles in the command design ...

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.