简单工厂?恩....
1namespace SimpleFactory
2{
3 /// <summary>
4 /// 员工的义务(拿了钱,总要还的)
5 /// </summary>
6 public interface IEmployeeDuty
7 {
8 //给别人打工的总要做些什么
9 void DoSomething();
10 }
11
12 /// <summary>
13 /// 职工应该都具备的
14 /// </summary>
15 public abstract class Employee:IEmployeeDuty
16 {
17 //活着.总要有个代号
18 private string name;
19 //一生总在各种不同的队伍中间徘徊..
20 private string department;
21
22 public string Department
23 {
24 get { return department; }
25 set { department = value; }
26 }
27 public string Name
28 {
29 get { return name; }
30 set { name = value; }
31 }
32
33 IEmployeeDuty 成员
39 }
40
41
42 /// <summary>
43 /// 程序员
44 /// </summary>
45 public class Programmer:Employee
46 {
47
48 public override void DoSomething()
49 {
50 Console.WriteLine(Name + " " + Department);
51 Console.WriteLine("埋头Coding.");
52 }
53 }
54
55 /// <summary>
56 /// 美工
57 /// </summary>
58 public class GraphicDesigner : Employee
59 {
60
61 public override void DoSomething()
62 {
63 Console.WriteLine(Name+" "+Department);
64 Console.WriteLine("我P..我P我Ps你.");
65 }
66 }
67
68 /// <summary>
69 /// - -! factory来了.
70 /// </summary>
71 public class ProjectManager
72 {
73 public static Employee DispatchWork(string work)
74 {
75 Employee employee = null;
76 switch (work)
77 {
78 case "ps":
79 employee = new GraphicDesigner(); break;
80 case "program":
81 employee = new Programmer(); break;
82 default:
83 break;
84 }
85 return employee;
86 }
87 }
88
89
90
91 /// <summary>
92 ///头儿的要求永远那么扑朔迷离
93 /// </summary>
94 class Boss
95 {
96 static void Main(string[] args)
97 {
98 Employee employee=null;
99
100 Console.WriteLine("这网页怎么这么难看!改!!");
101 employee = ProjectManager.DispatchWork("ps");
102 employee.Name = "张三";
103 employee.Department = "美工组";
104 employee.DoSomething();
105
106 Console.WriteLine("boos指着项目经理鼻子:客户需求又变了!你得给我换啊!!");
107 employee = ProjectManager.DispatchWork("program");
108 employee.Name = "李四";
109 employee.Department = "技术组";
110 employee.DoSomething();
111
112 Console.ReadKey();
113 }
114 }
115}
2{
3 /// <summary>
4 /// 员工的义务(拿了钱,总要还的)
5 /// </summary>
6 public interface IEmployeeDuty
7 {
8 //给别人打工的总要做些什么
9 void DoSomething();
10 }
11
12 /// <summary>
13 /// 职工应该都具备的
14 /// </summary>
15 public abstract class Employee:IEmployeeDuty
16 {
17 //活着.总要有个代号
18 private string name;
19 //一生总在各种不同的队伍中间徘徊..
20 private string department;
21
22 public string Department
23 {
24 get { return department; }
25 set { department = value; }
26 }
27 public string Name
28 {
29 get { return name; }
30 set { name = value; }
31 }
32
33 IEmployeeDuty 成员
39 }
40
41
42 /// <summary>
43 /// 程序员
44 /// </summary>
45 public class Programmer:Employee
46 {
47
48 public override void DoSomething()
49 {
50 Console.WriteLine(Name + " " + Department);
51 Console.WriteLine("埋头Coding.");
52 }
53 }
54
55 /// <summary>
56 /// 美工
57 /// </summary>
58 public class GraphicDesigner : Employee
59 {
60
61 public override void DoSomething()
62 {
63 Console.WriteLine(Name+" "+Department);
64 Console.WriteLine("我P..我P我Ps你.");
65 }
66 }
67
68 /// <summary>
69 /// - -! factory来了.
70 /// </summary>
71 public class ProjectManager
72 {
73 public static Employee DispatchWork(string work)
74 {
75 Employee employee = null;
76 switch (work)
77 {
78 case "ps":
79 employee = new GraphicDesigner(); break;
80 case "program":
81 employee = new Programmer(); break;
82 default:
83 break;
84 }
85 return employee;
86 }
87 }
88
89
90
91 /// <summary>
92 ///头儿的要求永远那么扑朔迷离
93 /// </summary>
94 class Boss
95 {
96 static void Main(string[] args)
97 {
98 Employee employee=null;
99
100 Console.WriteLine("这网页怎么这么难看!改!!");
101 employee = ProjectManager.DispatchWork("ps");
102 employee.Name = "张三";
103 employee.Department = "美工组";
104 employee.DoSomething();
105
106 Console.WriteLine("boos指着项目经理鼻子:客户需求又变了!你得给我换啊!!");
107 employee = ProjectManager.DispatchWork("program");
108 employee.Name = "李四";
109 employee.Department = "技术组";
110 employee.DoSomething();
111
112 Console.ReadKey();
113 }
114 }
115}