Design Pattern Examples
Overview of object-oriented design patterns
DesignPatternExamples_python.nullobject.nullobject_exercise Namespace Reference

Functions

def NullObject_Exercise ()
 Example of using the Null Object Pattern.
 

Function Documentation

◆ NullObject_Exercise()

def NullObject_Exercise ( void  )

Example of using the Null Object Pattern.

The Null Object pattern is where an object or function acts as a stand-in for real commands but otherwise does nothing.

In this exercise, movement commands are presented as characters in a string, with the characters 'u', 'd', 'l', and 'r' representing the moves "up", "down", "left", and "right", respectively. To keep the processing of this string simple, all other characters in the string are assigned a Null Object ("Do Nothing") version of the move command.

This example displays the commands after parsing and then "executes" commands, which consists of printing the commands out.

This example highlights the Null Object pattern while utilizing the Command Pattern and Interpreter Pattern.

Definition at line 28 of file nullobject_exercise.py.