-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobserver.cs
More file actions
57 lines (44 loc) · 1.13 KB
/
Copy pathobserver.cs
File metadata and controls
57 lines (44 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Collections;
using System.Collections.Generic;
public class Observer{
public Observer(){};
public Notify(Message message){
switch(message){
case EVENT_1:
// do something
break;
case EVENT_2:
// do something
break;
case NULL:
// raise an error
break;
default:
Console.WriteLine("Was notified but have nothing to do");
break;
}
}
}
public class Subject{
private List<Observer> _observerList;
public Subject(){
_observerList = new List<Observer>();
}
public void AddObserver(Observer observer){
_observerList.Add(observer);
}
public void RemoveObserver(Observer observer){
// might first need to check if observer is in the list
_observerList.Remove(observer)
}
public void NotifyObservers(Message message){
foreach(Observer myObserver in _observerList){
myObserver.Notify(message);
}
}
}
public enum Message{
EVENT_1,
EVENT_2,
NULL
}