工厂方法

 1 abstract class LeiFeng
 2     {
 3         public abstract void Sweep();
 4         public abstract void Wash();
 5         public abstract void BuyRice();
 6     }
 7 
 8     class Undergraduate : LeiFeng
 9     {
10         public override void Sweep()
11         {
12             Console.WriteLine("在校大学生,扫地");
13         }
14 
15         public override void Wash()
16         {
17             Console.WriteLine("在校大学生,洗衣");
18         }
19 
20         public override void BuyRice()
21         {
22             Console.WriteLine("在校大学生,买米");
23         }
24     }
25 
26     class Volunteer : LeiFeng
27     {
28         public override void Sweep()
29         {
30             Console.WriteLine("志愿者,扫地");
31         }
32 
33         public override void Wash()
34         {
35             Console.WriteLine("志愿者,洗衣");
36         }
37 
38         public override void BuyRice()
39         {
40             Console.WriteLine("志愿者,买米");
41         }
42     }
43 
44     interface IFactory
45     {
46         LeiFeng CreateLeiFeng();
47     }
48 
49     class UndergraduateFactory : IFactory
50     {
51         public LeiFeng CreateLeiFeng()
52         {
53             return new Undergraduate();
54         }
55     }
56 
57     class VolunteerFactory : IFactory
58     {
59         public LeiFeng CreateLeiFeng()
60         {
61             return new Volunteer();
62         }
63     }
工厂方法

转自《大话设计模式》

转载于:https://www.cnblogs.com/yixiu868/p/6557869.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值