-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractFactory.cs
More file actions
78 lines (77 loc) · 1.47 KB
/
AbstractFactory.cs
File metadata and controls
78 lines (77 loc) · 1.47 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//抽象工厂模式:提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类
using System;
interface IFactory
{
IProductA CreateProductA();
IProductB CreateProductB();
}
class ConcreteFactory1 : IFactory
{
public IProductA CreateProductA()
{
return new ProductA1();
}
public IProductB CreateProductB()
{
return new ProcuctB1();
}
}
class ConcreteFactory2 : IFactory
{
public IProductA CreateProductA()
{
return new ProductA2();
}
public IProductB CreateProductB()
{
return new ProcuctB2();
}
}
interface IProductA
{
void ShowA();
}
class ProductA1 : IProductA
{
public void ShowA()
{
Console.WriteLine("ProductA1");
}
}
class ProductA2 : IProductA
{
public void ShowA()
{
Console.WriteLine("ProductA2");
}
}
interface IProductB
{
void ShowB();
}
class ProcuctB1 : IProductB
{
public void ShowB()
{
Console.WriteLine("ProductB1");
}
}
class ProcuctB2 : IProductB
{
public void ShowB()
{
Console.WriteLine("ProductB2");
}
}
class Program
{
static void Main()
{
IFactory factory = new ConcreteFactory1();
IProductA productA = factory.CreateProductA();
productA.ShowA();
IProductB productB = factory.CreateProductB();
productB.ShowB();
Console.ReadKey();
}
}