Frage

Here in Russian Wikipedia link there is an example of C++ implementation of Command Design Pattern. As I understand from the implementation comparing with the UML class diagram I see that:

  1. class Document is the Invoker in the diagram
  2. class Command is the Command in the diagram
  3. class InsertCommand is the ConcreteCommand in the diagram
  4. class Receiver is the Receiver in the diagram

Also, as we can see from the diagram, Invoker aggregates Command. But in our case class Document does not aggregate the Command. Is it a mistake? Or is it a variation of Command pattern? How strict the UML diagram should be followed in general for designing a concrete pattern?

War es hilfreich?

Lösung

Namings for C++ example are not so good, I understand them as following:

  • Document is a Receiver, the object to apply the commands on
  • Receiver class acts as Invoker in terms of provided UML diagram.
  • main method is a Client

You could take a look at Java example, it is more clean.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top