Design Pattern Examples
Overview of object-oriented design patterns
state_exercise.py
Go to the documentation of this file.
1
6
7
from
.state_class
import
StateContext_Class
8
9
10
15
def
_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]
36
def
State_Exercise
():
37
print()
38
print(
"State Exercise"
)
39
40
filterContext =
StateContext_Class
()
41
textToFilter = \
42
'''/*#################### Block Comment
43
//
44
// A comment. /* A nested comment */
45
46
void
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]
DesignPatternExamples_python.state.state_class.StateContext_Class
Represents the State Machine to the application.
Definition:
state_class.py:30
DesignPatternExamples_python.state.state_exercise._State_DisplayText
None _State_DisplayText(str textToDisplay)
Helper method to display text from the State exercise.
Definition:
state_exercise.py:15
DesignPatternExamples_python.state.state_exercise.State_Exercise
def State_Exercise()
Example of using the State Pattern.
Definition:
state_exercise.py:36
python
DesignPatternExamples_python
state
state_exercise.py
Generated on Tue Aug 29 2023 19:47:44 for Design Pattern Examples by
1.9.6