|
2 | 2 |
|
3 | 3 | namespace StatePattern
|
4 | 4 | {
|
5 |
| -interface IWritingState { |
| 5 | + interface IWritingState |
| 6 | + { |
6 | 7 |
|
7 |
| - void Write(string words); |
| 8 | + void Write(string words); |
8 | 9 |
|
9 |
| -} |
| 10 | + } |
10 | 11 |
|
11 |
| -class UpperCase : IWritingState |
12 |
| -{ |
13 |
| - public void Write(string words) |
| 12 | + class UpperCase : IWritingState |
14 | 13 | {
|
15 |
| - Console.WriteLine(words.ToUpper()); |
| 14 | + public void Write(string words) |
| 15 | + { |
| 16 | + Console.WriteLine(words.ToUpper()); |
| 17 | + } |
16 | 18 | }
|
17 |
| -} |
18 | 19 |
|
19 |
| -class LowerCase : IWritingState |
20 |
| -{ |
21 |
| - public void Write(string words) |
| 20 | + class LowerCase : IWritingState |
22 | 21 | {
|
23 |
| - Console.WriteLine(words.ToLower()); |
| 22 | + public void Write(string words) |
| 23 | + { |
| 24 | + Console.WriteLine(words.ToLower()); |
| 25 | + } |
24 | 26 | }
|
25 |
| -} |
26 | 27 |
|
27 |
| -class DefaultText : IWritingState |
28 |
| -{ |
29 |
| - public void Write(string words) |
| 28 | + class DefaultText : IWritingState |
30 | 29 | {
|
31 |
| - Console.WriteLine(words); |
| 30 | + public void Write(string words) |
| 31 | + { |
| 32 | + Console.WriteLine(words); |
| 33 | + } |
32 | 34 | }
|
33 |
| -} |
34 | 35 |
|
35 |
| -class TextEditor { |
| 36 | + class TextEditor |
| 37 | + { |
36 | 38 |
|
37 |
| - private IWritingState mState; |
| 39 | + private IWritingState mState; |
38 | 40 |
|
39 |
| - public TextEditor() |
40 |
| - { |
41 |
| - mState = new DefaultText(); |
42 |
| - } |
| 41 | + public TextEditor() |
| 42 | + { |
| 43 | + mState = new DefaultText(); |
| 44 | + } |
43 | 45 |
|
44 |
| - public void SetState(IWritingState state) |
45 |
| - { |
46 |
| - mState = state; |
47 |
| - } |
| 46 | + public void SetState(IWritingState state) |
| 47 | + { |
| 48 | + mState = state; |
| 49 | + } |
48 | 50 |
|
49 |
| - public void Type(string words) |
50 |
| - { |
51 |
| - mState.Write(words); |
52 |
| - } |
| 51 | + public void Type(string words) |
| 52 | + { |
| 53 | + mState.Write(words); |
| 54 | + } |
53 | 55 |
|
54 |
| -} |
| 56 | + } |
55 | 57 |
|
56 | 58 | class Program
|
57 | 59 | {
|
|
0 commit comments