Using the command design pattern
The command design pattern generally involves encapsulating a command as an object. This is highly used in networking for games, in which player movements are sent across as objects that are run as commands. The four main points to remember in a command design pattern are the client, invoker, receiver, and command. The command object has knowledge of the receiver object. The receiver does the work after it receives a command. The invoker performs the command, without having any knowledge of who has sent the command. The client controls the invoker and decides which commands are to be performed at which stage.
Getting ready
For this recipe, you will need a Windows machine with a working copy of Visual Studio.
How to do it…
In this recipe, we will find out how easy it is to implement the command pattern:
Open Visual Studio.
Create a new C++ project console application.
Add the following lines of code:
#include <iostream> #include <conio.h> using namespace...