标签:[] string read creat people line nbsp 创建 adk
主方法
namespace 工厂方法 { class Program { static void Main(string[] args) { PeopleFactory peopleFactory = new PeopleFactory(); People p= peopleFactory.CreatePeople(); p.Say(); Console.ReadKey(); } } }
工厂方法
/// <summary> /// 优点: /// 1.延迟的对象的创建,可以加入一些逻辑 /// 2.实现对修改封闭对新增开发。 /// /// 缺点:实现用途不大 /// </summary> public class PeopleFactory { public People CreatePeople() { Console.WriteLine("创建人类做的其他事情。。。"); return new People(); } }
类
public class People { public void Say() { Console.WriteLine("人类说话了。。。"); } }
标签:[] string read creat people line nbsp 创建 adk
原文地址:http://www.cnblogs.com/zhuyapeng/p/7067847.html