![]()
public class order//菜单类
2 {
3 public Client customer;//顾客
4 public int id;//餐桌号
5 public string mealList;//点的菜单
6 }
1 public class Client//顾客类
2 {
3 //点餐
4 public void Order(waitress waitress, order or)
5 {
6 Console.WriteLine("顾客开始点菜:{0}!",or.mealList);
7 waitress.GetOrder(or);
8 }
9 //用餐
10 public void Eat()
11 {
12 Console.WriteLine("客人用餐!");
13 }
14 }
1 public class waitress//服务员类
2 {
3 private order or;
4 public void GetOrder(order or)
5 {
6 this.or = or;
7 }
8 //给厨师提交菜单
9 public void SendOrder(Chef chef)
10 {
11 Console.WriteLine("服务员将菜{0}传给厨师",or.mealList);
12 chef.GetOrder(or);
13
14 }
15 //传菜
16 public void TransCook(order or)
17 {
18 Console.WriteLine("服务员将菜{0}送给客户{1}!",or.mealList,or.id,or.customer);
19 or.customer.Eat();
20
21 }
22 }
1 public class Chef//厨师类
2 {
3 private order or;
4 public void GetOrder(order or)
5 {
6 this.or = or;
7 }
8 public void Cook()
9 {
10 Console.WriteLine("厨师烹制:{0}",or.mealList);
11 Console.WriteLine("制作完毕!");
12 }
13 public void SendAlert(waitress wait)
14 {
15 Console.WriteLine("厨师提示服务员取菜");
16 wait.GetOrder(or);
17 }
18 }
1 static void Main(string[] args)
2 {
3 //初始化顾客 服务员 厨师
4 Client wang = new Client();
5 waitress wait = new waitress();
6 Chef chef = new Chef();
7 //初始化菜单
8 order or = new order();
9 //设置订了该菜单的顾客
10 or.customer = wang;
11 or.id = 100;
12 or.mealList = "麻辣小龙虾";
13
14 wang.Order(wait, or);
15 wait.SendOrder(chef);
16
17 chef.Cook();
18 chef.SendAlert(wait);
19 wait.TransCook(or);
20 Console.ReadLine();
21 }
22 }