随笔分类 - design patterns
C# 设计模式
http://www.dofactory.com/Patterns/PatternFactory.aspx
Builder
摘要:定义:将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。通用类图:示例代码:View Code 1 // Builder pattern -- Structural example 2 3 using System; 4 5 using System.Collections.Generic; 6 7 8 namespace DoFactory.GangOfFour.Builder.Structural 9 10 { 11 12 /// <summary> 13 14 /// MainApp startup class for S...
阅读全文
Facade
摘要:定义:用于为子系统中的接口提供统一的接口。Facade设计模式定义了一个较高级的接口,它使得子系统的使用更加容易。UML:示例:View Code 1 // Facade pattern -- Structural example 2 3 4 using System; 5 6 7 namespace DoFactory.GangOfFour.Facade.Structural 8 9 { 10 11 /// <summary> 12 13 /// MainApp startup class for Structural 14 15 /// ...
阅读全文
Adapter
摘要:定义:将一个类的接口转换为另外一个用户所期望的接口。Adapter设计模式允许一些类可以共同运行,这些类因为具有不兼容的接口而不能使用其它的方法。UML:示例:View Code 1 // Adapter pattern -- Structural example 2 3 4 using System; 5 6 7 namespace DoFactory.GangOfFour.Adapter.Structural 8 9 { 10 11 /// <summary> 12 13 /// MainApp startup class for Stru...
阅读全文
Factory Method
摘要:定义:为创建对象定义一个接口,而让子类来决定哪一个类需要进行实例化。Factory Method设计模式允许一个类把实例化过程委托给子类。UML 类图: 示例代码:View Code 1 // Factory Method pattern -- Structural example 2 3 using System; 4 5 6 7 namespace DoFactory.GangOfFour.Factory.Structural 8 9 { 10 11 /// <summary> 12 13 /// MainApp startup clas...
阅读全文
Singleton
摘要:定义:确保一个类只有一个实例,并且提供全局访问点。示例:View Code 1 // Singleton pattern -- Structural example 2 3 4 using System; 5 6 7 namespace DoFactory.GangOfFour.Singleton.Structural 8 9 { 10 11 /// <summary> 12 13 /// MainApp startup class for Structural 14 15 /// Singleton Design Pattern. 16 ...
阅读全文
Abstract Factory 抽象工厂
摘要:定义:(GOF 含义)为创建相关的或与其有依赖关系的对象族提供一个接口,而无需分别为这些对象指定具体类。使用频率:高UML 类图:示例代码:View Code 1 // Abstract Factory pattern -- Structural example 2 3 4 using System; 5 6 namespace DoFactory.GangOfFour.Abstract.Structural 7 8 { 9 10 /// <summary> 11 12 /// MainApp startup class for Structura...
阅读全文
浙公网安备 33010602011771号