pub fn nullobject_exercise() -> Result<(), String>
Expand description

Example of using the “Null Object” design 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” the commands, which consists of printing the commands out.

This example highlights the ““Null Object”“ pattern while also utilizing the “Command” pattern and “Interpreter” pattern.