Design Pattern Examples
Overview of object-oriented design patterns
Decorator_Exercise.cs
Go to the documentation of this file.
1
5
6
using
System;
7
8
namespace
DesignPatternExamples_csharp
9
{
21
internal
class
Decorator_Exercise
22
{
26
// ! [Using Decorator in C#]
27
public
void
Run
()
28
{
29
Console.WriteLine();
30
Console.WriteLine(
"Decorator Exercise"
);
31
IRenderElement
baseElement =
new
TextElement
(
"This is raw text"
);
32
33
// Wrap the base element in three decorators.
34
IRenderElement
wrappedElement =
35
new
WhiteBackgroundDecorator
(
36
new
UnderlineDecorator
(
37
new
RedForegroundDecorator
(baseElement)));
38
39
// Now render the elements to the console.
40
Console.WriteLine(
" base Text element: \"{0}\""
, baseElement.
Render
());
41
Console.WriteLine(
" Decorated element: \"{0}\""
, wrappedElement.
Render
());
42
Console.WriteLine(
" Done."
);
43
}
44
// ! [Using Decorator in C#]
45
}
46
}
DesignPatternExamples_csharp.Decorator_Exercise
Example of using the Decorator Pattern in C#.
Definition:
Decorator_Exercise.cs:22
DesignPatternExamples_csharp.Decorator_Exercise.Run
void Run()
Executes the example for the Decorator Pattern in C#.
Definition:
Decorator_Exercise.cs:27
DesignPatternExamples_csharp.RedForegroundDecorator
Represents the RedForeground decorator, which renders the wrapped content as red text.
Definition:
Decorator_Classes.cs:145
DesignPatternExamples_csharp.TextElement
Represents the core element that can be decorated. Note that this class implements the IRenderElement...
Definition:
Decorator_Classes.cs:183
DesignPatternExamples_csharp.UnderlineDecorator
Represents the Underline decorator, which underlines the wrapped content.
Definition:
Decorator_Classes.cs:112
DesignPatternExamples_csharp.WhiteBackgroundDecorator
Represents the WhiteBackground decorator, which changes the background color of the wrapped element t...
Definition:
Decorator_Classes.cs:80
DesignPatternExamples_csharp.IRenderElement
Represents an element that can be rendered in text. All decorators and the core element class impleme...
Definition:
Decorator_Classes.cs:23
DesignPatternExamples_csharp.IRenderElement.Render
string Render()
Render this element as a string.
DesignPatternExamples_csharp
The namespace containing all Design Pattern Examples implemented in C#.
Definition:
Adapter_BackEndFunctions.cs:19
csharp
Decorator_Exercise.cs
Generated on Tue Aug 29 2023 19:47:44 for Design Pattern Examples by
1.9.6