-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
37 lines (30 loc) · 901 Bytes
/
Program.cs
File metadata and controls
37 lines (30 loc) · 901 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
37
using System;
using System.Collections.Generic;
namespace DesignPatterns.Observer
{
class Program
{
static void Main()
{
var shop = new Shop(new Dictionary<string, int> {
{ "salt", 2 },
{ "sugar", 2 },
{ "flour", 2 },
});
var shipper = new Shipper(shop);
var buyer = new Buyer(shop);
shop.Sell("salt", 1);
// Sugar goes out of stock here, shipper should respond.
shop.Sell("sugar", 2);
shop.Ship("flour", 1);
// Sugar went on sale, buyer should respond.
shop.Ship("sugar", 3);
// Shipper unsubscribes and will no longer respond if the goods run out.
shipper.Leave();
shop.Sell("flour", 3);
// Shipper unsubscribes and will no longer respond if the goods are back on sale.
buyer.Leave();
shop.Ship("flour", 1);
}
}
}