-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
48 lines (36 loc) · 1.12 KB
/
Program.cs
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
Page page = new Page();
page.Subscribe(new Subscriber("Ibrahim"));
page.Subscribe(new Subscriber("Tom"));
page.Subscribe(new Subscriber("Carton"));
page.Add("test1");
page.Update("test2");
page.Delete();
enum ChangeType
{
Add = 0, Update = 1, Delete = 2
}
record Subscriber(string name)
{
public void Update(Subscriber subscriber, Page page, ChangeType changeType)
=> Console.WriteLine($"Subscriber Name:{subscriber.name} Change Type:{changeType} Page Name:{page.GetName()}");
}
class Page
{
private string? name;
private readonly List<Subscriber> subscribers = new();
public string GetName() => name;
public void Update(String pageName)
{
this.name = pageName;
Notify(ChangeType.Update);
}
public void Add(String pageName)
{
this.name = pageName;
Notify(ChangeType.Add);
}
public void Delete() => Notify(ChangeType.Delete);
public void Subscribe(Subscriber subscriber) => this.subscribers.Add(subscriber);
private void Notify(ChangeType changeType) => subscribers.ForEach(subscriber => subscriber.Update(subscriber, this, changeType));
}