设计模式
alexjames_83
这个作者很懒,什么都没留下…
展开
-
设计模式inC#系列[1] Singleton 单件模式
把构造函数声明称隐式。通过静态方法Instance来访问类的实例。代码如下: class Program ...{ static void Main(string[] args) ...{ Singleton single = Singleton.Instance(); } } public class Singleton原创 2008-04-23 15:39:00 · 552 阅读 · 0 评论 -
设计模式[3] Adapter 适配器模式
James W. Cooper:“编写一个具有所需要的接口的类,然后让它和拥有不同接口的类进行通信。” (张志华等译) 说白了就是在不同接口的类外面再包一层。被包的那个类我们叫它Adaptee,包别人的那个类就叫Adapter。这样做的目的是:使一个或多个类的接口看起来像一个特定类的接口。 下面的例子中DListImpStack就是Adapter类, 而DList 被人包了,所以就是Adaptee原创 2008-05-21 14:26:00 · 457 阅读 · 0 评论 -
设计模式[4] Bridge Pattern 桥接模式
decouple an abstraction from its implementation so that the two can vary independently" (Gamma et al.)接口和实现分离,接口和实现的修改可以互不干扰。参与者: Abstraction (IShape) defines the abstraction原创 2008-05-21 15:19:00 · 465 阅读 · 0 评论 -
[Behavioral Patterns #1] Chain of responsibilty
GoF说:"Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request a原创 2008-08-04 14:37:00 · 457 阅读 · 0 评论 -
设计模式[8] Proxy Pattern 代理模式
GoF的定义是:Provide a surrogate or placeholder for another object to control access to it. 一个类的替身。说白了就是LazyLoad嘛。先定义一个基类,然后实际的类和代理类都来继承这个基类。代理类中包含个基类,客户调用基类的方法时,先到来调用代理类的方法,在这个方法中LazyLoad代理类的实例,然后再调用代理类的方原创 2008-05-25 19:29:00 · 537 阅读 · 0 评论 -
设计模式[5] Composite Pattern 组合模式
A tree structure of simple and composite objects说白了就是一树形结构嘛。有一个基类或者是接口,然后被Leaf和Composite分别继承或实现。Leaf只实现其中节点的基本操作, 而Composite则实现子节点的增加Add、删除Remove和获取GetChildren。贴张UML图原创 2008-05-24 09:12:00 · 440 阅读 · 0 评论 -
设计模式[7] Facade Pattern 外观模式
a pattern that provides an unified interface to access a set of interfaces in a subsystem. a higher-level interface that makes the subsystem easier to use. Typical example: In web apps, we have busine原创 2008-05-25 19:06:00 · 535 阅读 · 0 评论 -
设计模式[6] Decorator Pattern 装饰模式
Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. 附上UML图:看了代码就明白了:就是在一个基类外面再包一层。Decorator类的实例重载了基类的方法。把原创 2008-05-24 10:18:00 · 516 阅读 · 0 评论