Design Pattern Examples
Overview of object-oriented design patterns
NullObject_Exercise.cpp
Go to the documentation of this file.
1
6
7#include <iostream>
8
9#include "helpers/formatstring.h"
10
11#include "NullObject_Exercise.h"
12#include "Null_Object.h"
13
14
16{
17
37 // ! [Using NullObject in C++]
39 {
40 std::cout << std::endl;
41 std::cout << "NullObject Exercise" << std::endl;
42
43 MoveProcessor moveProcessor;
44
45 // A stream of recognized and unrecognized move commands. The
46 // unrecognized commands do nothing.
47 std::string moveString = "ur#ld!lr";
48 std::cout << " Showing the move commands:" << std::endl;
49 moveProcessor.ShowMoveList(moveString);
50
51 std::cout << " Executing the move commands:" << std::endl;
52 std::cout << Helpers::formatstring(" %s -> ", moveString.c_str());
53 moveProcessor.ExecuteMoveList(moveString);
54
55 std::cout << " Done." << std::endl;
56 }
57 // ! [Using NullObject in C++]
58
59} // end namespace
Implementation of the MoveProcessor class and the MoveCommand base class, along with the various Move...
Represents the processor that translates the move list into a list of MoveCommand objects then either...
Definition: Null_Object.h:274
void ExecuteMoveList(std::string moveList)
Parse and execute the given list of move commands, where each command is represents by a single chara...
Definition: Null_Object.h:376
void ShowMoveList(std::string moveList)
Parse and display the given list of move commands, where each command is represents by a single chara...
Definition: Null_Object.h:391
Declaration of the NullObject_Exercise() function as used in the Null Object Pattern.
The namespace containing all Design Pattern Examples implemented in C++.
void NullObject_Exercise()
Example of using the Null Object design pattern.
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....