Design patterns implementation examples

Command

Definition:

Encapsulates a request as an object - operation and its arguments are wrapped into an object. Thanks to this encapsulation creation of command lines and undo operation support is possible.


Example:

A good example is a scheduler in an operating system. For instance we want a computer to turn on a certain task (program) at given time and date. In the scheduler we define an operation/program which has to be done and what the program should do (operation arguments).


C++ code:

/src/command.cpp
Download source code

Command UML class diagram:
Command UML class diagram

Command UML sequence diagram:
Command UML sequence diagram