forked from danieldantasdev/DesignPatternsInUse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
20 lines (16 loc) · 857 Bytes
/
Program.cs
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."));