-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubject.cs
More file actions
35 lines (32 loc) · 896 Bytes
/
Subject.cs
File metadata and controls
35 lines (32 loc) · 896 Bytes
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
namespace observer_pattern
{
class ScoreSubject : ISubject
{
IList<IObserver> listObservers = new List<IObserver>();
private int score;
public int Score { get { return score; }
set {
score = value;
Notify();
} }
public void Register(IObserver observer) {
listObservers.Add(observer);
}
public void Unregister(IObserver observer) {
listObservers.Remove(observer);
}
public void Notify() {
listObservers.ToList().ForEach((observer) =>
{
observer.ScoreUpdated(Score);
});
}
}
}