File tree Expand file tree Collapse file tree
DesignPatterns/ObserverPattern/ObserverPattern Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Text ;
5+ using System . Threading . Tasks ;
6+
7+ namespace ObserverPattern
8+ {
9+ /// <summary>
10+ /// 抽象的观察者
11+ /// </summary>
12+ abstract class Observer
13+ {
14+ public abstract void Update ( ) ;
15+ }
16+
17+ class ConcreteObserver : Observer
18+ {
19+ private string observerName ;
20+ private string State ;
21+ private Subject subject ;
22+
23+
24+ public Subject GetSubject ( )
25+ {
26+ return this . subject ;
27+ }
28+
29+ public void SetSubject ( Subject subject )
30+ {
31+ this . subject = subject ;
32+ }
33+
34+ public ConcreteObserver ( Subject subject , string observerName )
35+ {
36+ this . subject = subject ;
37+ this . observerName = observerName ;
38+ }
39+
40+ public override void Update ( )
41+ {
42+ throw new NotImplementedException ( ) ;
43+ }
44+ }
45+ }
Original file line number Diff line number Diff line change 4343 </ItemGroup >
4444 <ItemGroup >
4545 <Compile Include =" Country.cs" />
46+ <Compile Include =" Observer.cs" />
4647 <Compile Include =" Program.cs" />
4748 <Compile Include =" Properties\AssemblyInfo.cs" />
4849 <Compile Include =" Spy.cs" />
50+ <Compile Include =" Subject.cs" />
4951 </ItemGroup >
5052 <ItemGroup >
5153 <None Include =" App.config" />
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Text ;
5+ using System . Threading . Tasks ;
6+
7+ namespace ObserverPattern
8+ {
9+ abstract class Subject
10+ {
11+ private List < Observer >
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments