Design Pattern Examples
Overview of object-oriented design patterns
decorator_exercise.py
Go to the documentation of this file.
1
6
7
from
.decorator_classes
import
WhiteBackgroundDecorator, UnderlineDecorator, RedForegroundDecorator, TextElement
8
9
10
19
20
# ! [Using Decorator in Python]
21
def
Decorator_Exercise
():
22
print()
23
print(
"Decorator Exercise"
)
24
25
baseElement =
TextElement
(
"This is raw text"
)
26
27
# Wrap the base element in three decorators.
28
wrappedElement = \
29
WhiteBackgroundDecorator
(
30
UnderlineDecorator
(
31
RedForegroundDecorator
(baseElement)
32
)
33
)
34
35
# Now render the elements to the console.
36
print(
" base Text element: \"{0}\""
.format(baseElement.Render()))
37
print(
" Decorated element: \"{0}\""
.format(wrappedElement.Render()))
38
39
print(
" Done."
)
40
# ! [Using Decorator in Python]
DesignPatternExamples_python.decorator.decorator_classes.RedForegroundDecorator
Represents the RedForeground decorator, which renders the wrapped content as red text.
Definition:
decorator_classes.py:117
DesignPatternExamples_python.decorator.decorator_classes.TextElement
Represents the core element that can be decorated.
Definition:
decorator_classes.py:151
DesignPatternExamples_python.decorator.decorator_classes.UnderlineDecorator
Represents the Underline decorator, which underlines the wrapped content.
Definition:
decorator_classes.py:91
DesignPatternExamples_python.decorator.decorator_classes.WhiteBackgroundDecorator
Represents the WhiteBackground decorator, which changes the background color of the wrapped element t...
Definition:
decorator_classes.py:65
DesignPatternExamples_python.decorator.decorator_exercise.Decorator_Exercise
def Decorator_Exercise()
Example of using the Decorator Pattern.
Definition:
decorator_exercise.py:21
python
DesignPatternExamples_python
decorator
decorator_exercise.py
Generated on Tue Aug 29 2023 19:47:44 for Design Pattern Examples by
1.9.6