Design Pattern Examples
Overview of object-oriented design patterns
MoveCommand Class Referenceabstract

Base class that represents a move command. A move command has a name and the command character that represents the command in the initial string of movement commands. More...

#include <Null_Object.h>

Inheritance diagram for MoveCommand:
Inheritance graph
Collaboration diagram for MoveCommand:
Collaboration graph

Public Types

using shared_ptr_t = std::shared_ptr< MoveCommand >
 Alias to make it easier to work with a shared pointer.
 

Public Member Functions

virtual ~MoveCommand ()
 Virtual destructor required for interfaces/base classes.
 
std::string Name ()
 Name of the command (assigned in the class constructor).
 
std::string Command ()
 The command character from the original list of commands. Used when displaying the commands as opposed to when executing the commands (assigned in the class constructor).
 
 MoveCommand (std::string command, std::string commandName)
 Constructor.
 
virtual void Show ()
 Display the move command and its name followed by a newline.
 
virtual void Execute ()=0
 Execute the command. Derived classes must implement this.
 

Private Attributes

std::string _name
 Name of the command.
 
std::string _command
 The command for controlling movement.
 

Detailed Description

Base class that represents a move command. A move command has a name and the command character that represents the command in the initial string of movement commands.

Yes, this is a variation of the Command Pattern.

In this example, a move command, when executed, prints "move xxx" on the current line. When displayed, the move command shows the command character followed by the name of the command.

Definition at line 32 of file Null_Object.h.

Member Typedef Documentation

◆ shared_ptr_t

using shared_ptr_t = std::shared_ptr<MoveCommand>

Alias to make it easier to work with a shared pointer.

Definition at line 38 of file Null_Object.h.

Constructor & Destructor Documentation

◆ ~MoveCommand()

virtual ~MoveCommand ( )
inlinevirtual

Virtual destructor required for interfaces/base classes.

Definition at line 55 of file Null_Object.h.

◆ MoveCommand()

MoveCommand ( std::string  command,
std::string  commandName 
)
inline

Constructor.

Parameters
commandThe character that represents the command in the original move list.
commandNameThe name of the command (for display purposes).

Definition at line 81 of file Null_Object.h.

Member Function Documentation

◆ Command()

std::string Command ( )
inline

The command character from the original list of commands. Used when displaying the commands as opposed to when executing the commands (assigned in the class constructor).

Definition at line 70 of file Null_Object.h.

References MoveCommand::_command.

◆ Execute()

virtual void Execute ( )
pure virtual

Execute the command. Derived classes must implement this.

Implemented in MoveCommandLeft, MoveCommandRight, MoveCommandUp, MoveCommandDown, and MoveCommandNone.

◆ Name()

std::string Name ( )
inline

Name of the command (assigned in the class constructor).

Definition at line 60 of file Null_Object.h.

References MoveCommand::_name.

Referenced by Visitor_Shop::PickupOrder(), Visitor_Shop::PlaceOrder(), and EntryInformation::ToString().

◆ Show()

virtual void Show ( )
inlinevirtual

Display the move command and its name followed by a newline.

Definition at line 91 of file Null_Object.h.

References MoveCommand::_command, MoveCommand::_name, and Helpers::formatstring().

Member Data Documentation

◆ _command

std::string _command
private

The command for controlling movement.

Definition at line 49 of file Null_Object.h.

Referenced by MoveCommand::Command(), and MoveCommand::Show().

◆ _name


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