-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShipper.cs
More file actions
36 lines (31 loc) · 820 Bytes
/
Shipper.cs
File metadata and controls
36 lines (31 loc) · 820 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
36
using System;
using System.Collections.Generic;
namespace DesignPatterns.Observer
{
using GoodsReminder = Dictionary<string, int>;
class Shipper : IObserver<GoodsReminder>
{
readonly IObservable<GoodsReminder> _observable;
public Shipper(IObservable<GoodsReminder> observable)
{
observable.Register(this);
_observable = observable;
}
public void Update(GoodsReminder value)
{
foreach (var entry in value)
{
if (entry.Value < 1)
{
Console.WriteLine($"[Shipper] {entry.Key[..1].ToUpper() + entry.Key[1..]} is" +
" out of stock, we need to ship some.");
}
}
}
public void Leave()
{
Console.WriteLine("[Shipper] I'm no longer shipping goods here.");
_observable.Unregister(this);
}
}
}