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

Example of using the State Pattern in C#. More...

Collaboration diagram for State_Exercise:
Collaboration graph

Public Member Functions

void Run ()
 Executes the example for the State Pattern in C#.
 

Private Member Functions

void _State_DisplayText (string textToDisplay)
 Helper method to display text from the State exercise. Text is displayed with line numbers.
 

Detailed Description

Example of using the State Pattern in C#.

The State pattern alters the behavior of the class hierarchy based on some state. This is the basis of a Finite State Machine.

In this exercise, the State class is a filter that parses text to remove C++-style line and block comments. It needs to be smart enough to ignore comment characters inside quotes.

The filtering process starts with creating the context that drives the state machine. Internal classes are provided for each state.

Definition at line 23 of file State_Exercise.cs.

Member Function Documentation

◆ _State_DisplayText()

void _State_DisplayText ( string  textToDisplay)
inlineprivate

Helper method to display text from the State exercise. Text is displayed with line numbers.

Parameters
textToDisplayText to display.

Definition at line 31 of file State_Exercise.cs.

Referenced by State_Exercise.Run().

◆ Run()

void Run ( )
inline

Executes the example for the State Pattern in C#.

Definition at line 46 of file State_Exercise.cs.

References State_Exercise._State_DisplayText(), StateContext_Class.RemoveComments(), and textToFilter.

Referenced by Program.Run().


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