forked from WeihanLi/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaiter.cs
More file actions
37 lines (33 loc) · 954 Bytes
/
Waiter.cs
File metadata and controls
37 lines (33 loc) · 954 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 CommandPattern
{
public class Waiter
{
private readonly ICollection<OrderCommand> _orders = new List<OrderCommand>();
public void SetOrder(OrderCommand order)
{
if (order.ToString() == "BakeChickenWingCommand")
{
Console.WriteLine("鸡翅没有了,换点别的吧");
}
else
{
Console.WriteLine($"{order} 下单成功");
_orders.Add(order);
}
}
public void CancelOrder(OrderCommand order)
{
_orders.Remove(order);
Console.WriteLine($"取消订单:{order},取消时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
}
public void Notify()
{
foreach (var order in _orders)
{
order.ExecuteCommand();
}
}
}
}