最近在看设计模式,故事好玩是好玩,可是代码也很多啊,有时候看图不太理解,为了让自己有兴趣并且坚持下去,在第一遍宏观的看了一遍之后,把23种设计模式进行了一下分类,然后再找类似的模式一起学习,通过对比学习再理解,确实是容易了一些。先学的创建型模式里的工厂三姐妹,一块学习这三个模式,比较一下它们的优缺点,知道什么时候要用什么模式。
static void Main(string [] args)
{
User user = new User();
Department department = new department();
IUser su=DataAccess.CreateUser ();
su.Insert(user);
su.GetUser(1);
IDepartment ide = DataAccess.CreateDepartment();
ide.Insert(department);
ide.GetDepartment(343);
Console.Read();
}static void Main(string [] args)
{
User user = new User();
Ifactory factory=new AccessFactory();
IUser su=factory.CreateUser ();
su.Insert(user);
su.GetUser(1);
Console.Read();
}static void Main(string [] args)
{
User user = new User();
Department department = new Department();
Ifactory factory=new AccessFactory();//确定实例化哪一个数据库访问对象给factory
IUser su=factory.CreateUser ();//与具体的数据库解除了依赖
su.Insert(user);
su.GetUser(1);
IDepartment ide = factory.CreateDepartment();
ide.Insert(department);
ide.GetDepartment(343);
Console.Read();
}原文地址:http://blog.csdn.net/luckystar689/article/details/41913271