摘要: 应用场景:客户代码过多的依赖对象容器的复杂的内部实现,对象容器内部的变化将导致客户端的代码的剧烈变化。将客户代码和对象容器解耦,从而更能够应对变化。实现代码: public interface IBox { void Process(); void Add(IBox box); void Remove(IBox box); } public class SingleBox : IBox { public void Process() { // do process for myself } public void Add(IBox box) { // 两个实现方案 // 1. do noth 阅读全文
posted @ 2010-07-21 13:40 qiang.xu 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 应用场景:解决的是在需求中,面临两个需求维度的变化的话,可以使用Bridge模式。实现代码: //------------------------------------------------------- // Tank 2.0 // 两个方向的变化,一中是平台,另外一中是类型的变化。 // 将事物中多个维度的变化分离,使得其能够独立的变化。 // 一个类只能有一个变化原因。 //--------------------------------------------------------------- public abstract class Tank { protected Tan 阅读全文
posted @ 2010-07-21 12:33 qiang.xu 阅读(176) 评论(0) 推荐(0) 编辑
摘要: Get here : http://www.codeproject.com/KB/cs/cs_interfaces.aspxIntroductionInterfaces in C # provide a way to achieve runtime polymorphism. Using interfaces we can invoke functions from different classes through the same Interface reference, whereas using virtual functions we can invoke functions fro 阅读全文
posted @ 2010-07-21 10:36 qiang.xu 阅读(415) 评论(0) 推荐(1) 编辑
摘要: 使用场景:将现有系统应用到新系统中,但是两个系统接口是不相同的,这里使用adapter模式类解决这个问题。实现代码:// 现有类 class ExistingClass { public void SpecificRequest1() { } public void SpecificRequest2() { } // ... } // 新环境所使用的接口 interface ITarget { void Request(); } // 另外一个系统 class MySystem { public void Process(ITarget target) // 面向接口编程 { // 这里可以直 阅读全文
posted @ 2010-07-21 09:49 qiang.xu 阅读(170) 评论(0) 推荐(0) 编辑