forked from sheng-jie/Design-Pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractFactory.cs
More file actions
51 lines (46 loc) · 1.24 KB
/
Copy pathAbstractFactory.cs
File metadata and controls
51 lines (46 loc) · 1.24 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryPattern
{
/// <summary>
/// 抽象工厂模式:
/// 抽象工厂是应对产品族概念的,比如说,每个汽车公司可能要同时生产轿车,货车,客车,那么每一个工厂都要有创建轿车,货车和客车的方法。
/// 应对产品族概念而生,增加新的产品线很容易,但是无法增加新的产品。
/// </summary>
public interface IAbstractFactory
{
AbstractCar CreateCar();
AbstractBus CreateBus();
}
/// <summary>
/// 宝马工厂
/// </summary>
public class BMWFactory:IAbstractFactory
{
public AbstractCar CreateCar()
{
return new ConcreateCarA();
}
public AbstractBus CreateBus()
{
return new ConcreateBusA();
}
}
/// <summary>
/// 比亚迪工厂
/// </summary>
public class BYDFactory : IAbstractFactory
{
public AbstractCar CreateCar()
{
return new ConcreateCarB();
}
public AbstractBus CreateBus()
{
return new ConcreateBusB();
}
}
}