1 using System;
2
3 namespace ConsoleApp1
4 {
5 class Program
6 {
7 static void Main(string[] args)
8 {
9 ShengChanGongChang shengChanGongChang = new ShengChanGongChang();
10 BaoZhuangGongChcnag baoZhuangGongChcnag = new BaoZhuangGongChcnag();
11
12 Func<Product> func1 = new Func<Product>(shengChanGongChang.DaBing);
13 Func<Product> func2 = new Func<Product>(shengChanGongChang.ChouDouFu);
14
15 baoZhuangGongChcnag.BaoZhuang(func1);
16 baoZhuangGongChcnag.BaoZhuang(func2);
17 }
18 }
19 class Product
20 {
21 /// <summary>
22 /// 产品名称
23 /// </summary>
24 public string Name { get; set; }
25 }
26 class Box
27 {
28 /// <summary>
29 /// 产品实物
30 /// </summary>
31 public Product Product { get; set; }
32 }
33 // 包装工厂
34 class BaoZhuangGongChcnag
35 {
36 public Box BaoZhuang(Func<Product> getProduct)
37 {
38 Box box = new Box();
39 Product product = getProduct.Invoke();
40 box.Product = product;
41 return box;
42 }
43 }
44 // 生产工厂
45 class ShengChanGongChang
46 {
47 public Product DaBing()
48 {
49 Product product = new Product();
50 product.Name = "大饼";
51 return product;
52 }
53 public Product ChouDouFu()
54 {
55 Product product = new Product();
56 product.Name = "臭豆腐";
57 return product;
58 }
59 }
60 }