Design Pattern Examples
Overview of object-oriented design patterns
state_exercise.py
Go to the documentation of this file.
6
7from .state_class import StateContext_Class
8
9
10
15def _State_DisplayText(textToDisplay : str) -> None:
16 lines = textToDisplay.split('\n')
17 lineNumber = 1
18 for line in lines:
19 print(" {0:2}) {1}".format(lineNumber, line))
20 lineNumber += 1
21
22
23
34
35# ! [Using State in Python]
37 print()
38 print("State Exercise")
39
40 filterContext = StateContext_Class()
41 textToFilter = \
42'''/*#################### Block Comment
43//
44// A comment. /* A nested comment */
45
46void State_Exercise() // An exercise in state machines
47{
48 char character = '\\"';
49 std::cout << std::endl;
50 std::cout << "\\"State\\" /*Exercise*/" << std::endl;
51
52 StateContext_Class filterContext;
53
54 std::cout << "\\t\\tDone. //(No, really)//" << std::endl;
55}'''
56 print(" Text to filter:")
57 _State_DisplayText(textToFilter)
58
59 print(" Filtering text...")
60 filteredText = filterContext.RemoveComments(textToFilter)
61
62 print(" Filtered text:")
63 _State_DisplayText(filteredText)
64
65 print(" Done.")
66# ! [Using State in Python]
Represents the State Machine to the application.
Definition: state_class.py:30
None _State_DisplayText(str textToDisplay)
Helper method to display text from the State exercise.
def State_Exercise()
Example of using the State Pattern.