主讲:李建忠
来源:
1: abstract class StatedDocument //抽象类——表达状态及依赖状态的行为
2: {
3: public abstract void Handle1();
4: public abstract void Handle2();
5: public abstract void Handle3();
6:
7: public abstract StatedDocument Next
8: {
9: get;
10: set;
11: }
12: }
13:
14: class Document //主逻辑
15: {
16: StatedDocument statedDocument;
17:
18: public void SetStatedDocument(StatedDocument statedDocument)
19: {
20: this.statedDocument=statedDocument;
21: }
22:
23: public void Handle1()
24: {
25: statedDocument.Handle1();
26: statedDocument=statedDocument.Next;
27: }
28:
29: public void Handle2()
30: {
31: statedDocument.Handle2();
32: }
33:
34: public void Handle3()
35: {
36: statedDocument.Handle3();
37: }
38: }