forked from Run2948/CSharpDesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (51 loc) · 1.74 KB
/
Program.cs
File metadata and controls
57 lines (51 loc) · 1.74 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
using FactoryPattern.War3.Interface;
using FactoryPattern.War3.Service;
using FactoryPattern.War3.ServiceExtend;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryMethodPattern
{
/// <summary>
/// 1 对比简单工厂,建立工厂方法(FactoryMethod)
/// 2 工厂方法的优缺点和应用
/// </summary>
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("欢迎来到.net高级班公开课之设计模式特训,今天是Eleven老师为大家带来的工厂方法设计模式");
{
Human human = new Human();
Undead undead = new Undead();
NE ne = new NE();
ORC orc = new ORC();
//Six six=new Six()//参数信息很麻烦
}
{
IRace human = new Human();
IRace undead = new Undead();
IRace ne = new NE();
IRace orc = new ORC();
}
{
IFactory humanFactory = new HumanFactory();
IRace human = humanFactory.CreateInstance();
IFactory fiveFactory = new FiveFactory();
IRace five = fiveFactory.CreateInstance();
IFactory sixFactory = new SixFactoryExtend();// new SixFactory();
IRace six = sixFactory.CreateInstance();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.Read();
}
}
}