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...

Collaboration diagram for MoveProcessor:
Collaboration graph

Public Member Functions

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

Private Member Functions

List< MoveCommand_ParseMoves (string moveList)
 Helper method to convert a list of single letter commands into a list of MoveCommand objects.
 
void _ExecuteMoves (List< MoveCommand > commands)
 Helper method to execute all the given commands.
 
void _ShowMoves (List< MoveCommand > 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 231 of file Null_Object.cs.

Member Function Documentation

◆ _ExecuteMoves()

void _ExecuteMoves ( List< MoveCommand 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 301 of file Null_Object.cs.

Referenced by MoveProcessor.ExecuteMoveList().

◆ _ParseMoves()

List< MoveCommand > _ParseMoves ( 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 249 of file Null_Object.cs.

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

◆ _ShowMoves()

void _ShowMoves ( List< MoveCommand 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 320 of file Null_Object.cs.

Referenced by MoveProcessor.ShowMoveList().

◆ ExecuteMoveList()

void ExecuteMoveList ( 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 339 of file Null_Object.cs.

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

Referenced by NullObject_Exercise.Run().

◆ ShowMoveList()

void ShowMoveList ( 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 354 of file Null_Object.cs.

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

Referenced by NullObject_Exercise.Run().


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