Design Pattern Examples
Overview of object-oriented design patterns
MoveProcessor Class Reference

Represents the processor that translates the move list into a list of MoveCommand objects then either displays them or executes them. More...

#include <Null_Object.h>

Collaboration diagram for MoveProcessor:
Collaboration graph

Public Member Functions

void ExecuteMoveList (std::string moveList)
 Parse and execute the given list of move commands, where each command is represents by a single character.
 
void ShowMoveList (std::string moveList)
 Parse and display the given list of move commands, where each command is represents by a single character.
 

Private Member Functions

std::vector< MoveCommand::shared_ptr_t_ParseMoves (std::string moveList)
 Helper method to convert a list of single letter commands into a list of MoveCommand objects.
 
void _ExecuteMoves (const std::vector< MoveCommand::shared_ptr_t > &commands)
 Helper method to execute all the given commands.
 
void _ShowMoves (const std::vector< MoveCommand::shared_ptr_t > &commands)
 Display the command character and name of the command for each command in the given list of commands.
 

Detailed Description

Represents the processor that translates the move list into a list of MoveCommand objects then either displays them or executes them.

This classes uses a parser to convert the single letter characters in a string into a list of actions (instances of the MoveCommand class). This list of actions is then executed to perform the operations.

This process of executing the list of operations is an example of the Command Pattern. This is also an example of the Interpreter Pattern, where the actions are the tokens to be interpreted.

Definition at line 273 of file Null_Object.h.

Member Function Documentation

◆ _ExecuteMoves()

void _ExecuteMoves ( const std::vector< MoveCommand::shared_ptr_t > &  commands)
inlineprivate

Helper method to execute all the given commands.

Parameters
commandsA list of MoveCommand objects to "execute".

In this implementation, the MoveCommand object prints the command as "<move xxx> " on the current line. When all commands have been printed, a new line is printed to move to the next line. The "Do Nothing" command doesn't print anything, leaving only the empty <>.

Definition at line 339 of file Null_Object.h.

Referenced by MoveProcessor::ExecuteMoveList().

◆ _ParseMoves()

std::vector< MoveCommand::shared_ptr_t > _ParseMoves ( std::string  moveList)
inlineprivate

Helper method to convert a list of single letter commands into a list of MoveCommand objects.

This method recognizes 'L', 'R', 'U', and 'D' (case-insensitive). All other characters default to the "Do Nothing" (Null Object) command.

Parameters
moveListA string containing a list of single letter commands to be parsed.
Returns
Returns a list of MoveCommand objects.

Definition at line 289 of file Null_Object.h.

Referenced by MoveProcessor::ExecuteMoveList(), and MoveProcessor::ShowMoveList().

◆ _ShowMoves()

void _ShowMoves ( const std::vector< MoveCommand::shared_ptr_t > &  commands)
inlineprivate

Display the command character and name of the command for each command in the given list of commands.

Parameters
commandsThe list of MoveCommand objects to display.

Definition at line 356 of file Null_Object.h.

Referenced by MoveProcessor::ShowMoveList().

◆ ExecuteMoveList()

void ExecuteMoveList ( std::string  moveList)
inline

Parse and execute the given list of move commands, where each command is represents by a single character.

Recognizes 'U', 'D', 'L', and 'R' (case-insensitive). All other characters are assigned a "Do Nothing" (Null Object) command.

Parameters
moveListA string of characters to parse and execute.

Definition at line 376 of file Null_Object.h.

References MoveProcessor::_ExecuteMoves(), and MoveProcessor::_ParseMoves().

Referenced by DesignPatternExamples_cpp::NullObject_Exercise().

◆ ShowMoveList()

void ShowMoveList ( std::string  moveList)
inline

Parse and display the given list of move commands, where each command is represents by a single character.

Recognizes 'U', 'D', 'L', and 'R' (case-insensitive). All other characters are assigned a "Do Nothing" (Null Object) command.

Parameters
moveListA string of characters to parse and display.

Definition at line 391 of file Null_Object.h.

References MoveProcessor::_ParseMoves(), and MoveProcessor::_ShowMoves().

Referenced by DesignPatternExamples_cpp::NullObject_Exercise().


The documentation for this class was generated from the following file: