随笔分类 -  设计模式

摘要:设计模式是软件开发讨论中,亘古不变的话题,今天又拿出来说道两句,也是对设计模式的一个复习吧。 工厂方法模式 工厂方法模型定义了一个用于创建对象的接口,让子类决定实例化哪一个类,工厂模式使一个类的实例化延迟到了其子类中。工厂方法模式是优化的简单工厂模式,它很好的支持了“开闭原则”。每一个具体的工厂只能 阅读全文
posted @ 2016-03-11 12:09 好好學習 阅读(337) 评论(0) 推荐(0)
摘要:抽象工廠用例圖 代碼 class Program { static void Main(string[] args) { User user = new User(); Department dept = new Department(); IUser iu = DataAccess.CreateU 阅读全文
posted @ 2016-03-11 11:51 好好學習 阅读(154) 评论(0) 推荐(0)
摘要:觀察者用例圖 代碼 class Program { static void Main(string[] args) { ConcreteSubject s = new ConcreteSubject(); s.Attach(new ConcreteObserver(s, "X")); s.Attac 阅读全文
posted @ 2016-03-11 11:50 好好學習 阅读(149) 评论(0) 推荐(0)
摘要:建造者模式用例圖 代碼 class Program { static void Main(string[] args) { Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = ne 阅读全文
posted @ 2016-03-11 11:48 好好學習 阅读(184) 评论(0) 推荐(0)
摘要:外觀模式用例圖 外觀模式的基本代碼 class Program { static void Main(string[] args) { Facade facade = new Facade(); facade.MethodA(); facade.MethodB(); Console.Read(); 阅读全文
posted @ 2016-03-11 11:47 好好學習 阅读(167) 评论(0) 推荐(0)
摘要:模板方法模式用例图 class Program { static void Main(string[] args) { AbstractClass c; c = new ConcreteClassA(); c.TemplateMethod(); c = new ConcreteClassB(); c 阅读全文
posted @ 2016-03-10 23:37 好好學習 阅读(185) 评论(0) 推荐(0)
摘要:原型模式用例图 class Program { static void Main(string[] args) { Resume a = new Resume("大鸟"); a.SetPersonalInfo("男", "29"); a.SetWorkExperience("1998-2000", 阅读全文
posted @ 2016-03-10 23:18 好好學習 阅读(185) 评论(0) 推荐(0)
摘要:工厂方法用例图 运算类及其实现方法 /// <summary> /// 运算类 /// </summary> class Operation { private double _numberA = 0; private double _numberB = 0; public double Numbe 阅读全文
posted @ 2016-03-10 23:13 好好學習 阅读(148) 评论(0) 推荐(0)
摘要:代理模式用例图 class Program { static void Main(string[] args) { Proxy proxy = new Proxy(); proxy.Request(); Console.Read(); } } abstract class Subject { pub 阅读全文
posted @ 2016-03-10 23:04 好好學習 阅读(135) 评论(0) 推荐(0)
摘要:装饰模式用例图 class Program { static void Main(string[] args) { ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecorator 阅读全文
posted @ 2016-03-10 22:56 好好學習 阅读(158) 评论(0) 推荐(0)
摘要:策略模式的用例图 定义一个算法抽象策略类 //抽象算法类 abstract class Strategy { //算法方法 public abstract void AlgorithmInterface(); } 通过继承实现具体的算法 //具体算法A class ConcreteStrategyA 阅读全文
posted @ 2016-03-10 22:34 好好學習 阅读(149) 评论(0) 推荐(0)
摘要:简单工厂模式uml例图 实现代码基本如下 创建一个运算类 /// <summary> /// 运算类 /// </summary> public class Operation { private double _numberA = 0; private double _numberB = 0; / 阅读全文
posted @ 2016-03-10 21:44 好好學習 阅读(167) 评论(0) 推荐(0)
摘要:大话设计模式中的利用反射加抽象工厂的数据访问程序。先来看看反射技术的基本格式:--反射工廠 Assembly.Load(“程序集名称”).CreateInstance(“命名空间.类名称”); 只要在程序顶端写上using System.Reflection来引用Reflection,就可以采用反射 阅读全文
posted @ 2016-03-10 13:53 好好學習 阅读(187) 评论(0) 推荐(0)