FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
DesignPatternsInUse/src/State/Program.cs at master · danieldantasdev/DesignPatternsInUse · GitHub
danieldantasdev
/
DesignPatternsInUse
Public
Notifications
You must be signed in to change notification settings
Fork
128
Star
5
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
DesignPatternsInUse
/
src
/
State
/
Program.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
20 lines (16 loc) · 857 Bytes
Breadcrumbs
DesignPatternsInUse
/
src
/
State
/
Program.cs
Copy path
File metadata and controls
20 lines (16 loc) · 857 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* In this example, TextEditor uses different ITextState implementations
* to alter how text is formatted based on the current state.
* When the state changes (e.g., to bold or italic), the TypeText method
* formats the text according to the rules defined in the current state.
* This approach cleanly separates the concerns of text formatting from the
* editor logic, making it easy to add new styles or modify existing ones
* without changing the TextEditor class. */
TextEditor
editor
=
new
TextEditor
(
)
;
// Typing in normal state
Console
.
WriteLine
(
editor
.
TypeText
(
"This is normal text."
)
)
;
// Change state to bold
editor
.
SetState
(
new
BoldTextState
(
)
)
;
Console
.
WriteLine
(
editor
.
TypeText
(
"This is bold text."
)
)
;
// Change state to italic
editor
.
SetState
(
new
ItalicTextState
(
)
)
;
Console
.
WriteLine
(
editor
.
TypeText
(
"This is italic text."
)
)
;
Back
|
FazBrowse Home
|
New Git URL