随笔分类 -  Design Pattern设计模式

摘要:结构设计模式向您展示了如何以灵活和可扩展的方式将系统的不同部分粘合在一起。它们可以帮助您保证当其中一个部分发生更改时,整个结构不需要更改。这些模式关注的是类之间如何相互继承,以及它们是如何由其他类组成的。结构模式使用继承来组合接口或实现。 适配器模式 适配器模式(Adapter Pattern)是作 阅读全文
posted @ 2020-03-31 17:11 昕友软件开发 阅读(368) 评论(0) 推荐(0) 编辑
摘要:行为设计模式是识别对象之间的通信模式,行为模式涉及对象之间的责任分配,或者,将行为封装在对象中并将请求委托给它,也就是对象之间的关系。 涉及:* 状态模式中介模式* 观察者模式备忘录模式迭代器模式命令模式* 策略模式* 模板模式* 访客模式示例责任链模式 观察者模式 根据GoF定义,observer 阅读全文
posted @ 2020-03-27 20:57 昕友软件开发 阅读(298) 评论(0) 推荐(0) 编辑
摘要:行为设计模式是识别对象之间的通信模式,行为模式涉及对象之间的责任分配,或者,将行为封装在对象中并将请求委托给它,也就是对象之间的关系。 涉及: 状态模式 * 中介模式 观察者模式 * 备忘录模式 * 迭代器模式 * 命令模式 策略模式 模板模式 访客模式示例 * 责任链模式 责任链模式 责任链模式( 阅读全文
posted @ 2020-03-27 10:36 昕友软件开发 阅读(398) 评论(0) 推荐(0) 编辑
摘要:单例模式 懒汉式,线程不安全。 除非是单线程程序,否则不推荐使用。 public class Singleton { private static Singleton instance; private Singleton (){} public static Singleton getInstan 阅读全文
posted @ 2020-03-26 10:27 昕友软件开发 阅读(265) 评论(0) 推荐(0) 编辑
摘要:得益于函数接口,我们可以改造设计模式(不限于此): 策略模式 模板模式 观察者模式 责任链模式 工厂模式 策略模式 优点: 1、算法可以自由切换。 2、避免使用多重条件判断。 3、扩展性良好。 缺点: 1、策略类会增多。 2、所有策略类都需要对外暴露。 使用场景: 1、如果在一个系统里面有许多类,它 阅读全文
posted @ 2020-03-04 11:31 昕友软件开发 阅读(827) 评论(0) 推荐(1) 编辑
摘要:在企业IM开发中,经常用到和业务系统的数据交换,在中国企业最常见的比如组织架构变更,一般在客户端加密保存了组织架构树(便于快速的查询和树展示),当HR或OA或AD域这些管控企业组织架构的数据发生改变,需要IM服务器推送最新的组织架构,如果推送整个组织架构,数据量非常大(千人以上时),恰当的方式是:仅... 阅读全文
posted @ 2015-10-08 10:33 昕友软件开发 阅读(922) 评论(0) 推荐(1) 编辑
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Xml.Linq;using System.Reflection;using System.Xml;using 阅读全文
posted @ 2011-05-19 23:34 昕友软件开发 阅读(276) 评论(0) 推荐(0) 编辑
摘要:有一篇技巧,见http://tech.sina.com.cn/s/2008-07-03/1528718607.shtml或http://kb.cnblogs.com/page/42897/?page=1讨论的是运用InitParams在Silverlight 2应用程序中切换用户控件,这是个很笨但是直观的解决方式。但如果在控件中传值,那将怎么办?以上方法将毫无用途!今天在一个老外的博客看到有个很巧... 阅读全文
posted @ 2009-07-10 17:30 昕友软件开发 阅读(257) 评论(0) 推荐(0) 编辑
摘要:状态模式using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace State{ public interface State { //投入25分硬币 void insertQuarter(); //退出硬币 void ejectQuarter(); //推把手 void t... 阅读全文
posted @ 2009-07-08 16:16 昕友软件开发 阅读(252) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Strategy{ /// summary /// 具有飞行行为 /// /summary public interface FlyBehavior { void fly(); } /// summary /// 具有吃饭行为 /// /summary public interface EatBehavior { void eat(); } /// summary /// 用翅膀飞 /// 阅读全文
posted @ 2009-07-08 16:12 昕友软件开发 阅读(219) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace SingleTon{ public sealed class SingleObject { //公有字段 public string name; //类似java的实现 private static object s... 阅读全文
posted @ 2009-07-08 16:10 昕友软件开发 阅读(197) 评论(0) 推荐(0) 编辑
摘要:观察者,被观察实时数据推送给观察者using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Observer{ interface Subject { void register(Observer o); void remove(Observer o); void notify(); } interface Observer { void update(float temp); } interface Dispaly { void display(); }}using 阅读全文
posted @ 2009-07-08 16:09 昕友软件开发 阅读(181) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Collections;namespace Iterator{ public class Item { string name; double price; public Item(string n, double p) { this.name = n; this.price = p; } public string getName() { return name; } public double get 阅读全文
posted @ 2009-07-08 16:07 昕友软件开发 阅读(183) 评论(0) 推荐(0) 编辑
摘要:饮料的包装using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Decorator{ //抽象组件类 饮料 public abstract class Beverage { public string description = "未知描述"; public Size size; public abstract Size getsize(); public abstract string getDescription(); public abstract doubl 阅读全文
posted @ 2009-07-08 16:03 昕友软件开发 阅读(192) 评论(0) 推荐(0) 编辑
摘要:用一个控制器(带有几个开关)来控制所有的电器?神奇而简单的实现:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Command{ public interface Command { void execute(); void execute1(); void execute2(); }}using System;using System.Collections.Generic;using System.Linq;using System.Text;namesp 阅读全文
posted @ 2009-07-08 15:51 昕友软件开发 阅读(220) 评论(0) 推荐(0) 编辑
摘要:原作是把一只火鸡通过一个适配器,出来后就是一只鸭,神奇。改成C#的代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Adapter{ /// summary /// 鸭子接口 /// /summary public interface Duck { //可以咵咵的叫 void quack(); void fly(); } /// summary /// 火鸡接口 /// /summary public interface Turkey { 阅读全文
posted @ 2009-07-08 15:46 昕友软件开发 阅读(200) 评论(0) 推荐(0) 编辑
摘要:这个或许叫源-监听器(Source/Listener)模式更加形象。 观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象。这个主题对象在状态上发生变化时,会通知所有观察者对象,使它们能够自动更新自己。 participants The classes and/or objects participating in this pattern are: ... 阅读全文
posted @ 2008-12-22 11:19 昕友软件开发 阅读(171) 评论(0) 推荐(0) 编辑
摘要:主要用途是对聚集采取某种操作,统一执行。 访问者模式适用于数据结构相对未定的系统,它把数据结构和作用于结构上的操作之间的耦合解脱开,使得操作集合可以相对自由地演化。 比如雇员对象,我们先只有名称、年龄、工资这些属性,可以先定义访问者类来分离结构和操作 participants The classes and/or objects participating in this pat... 阅读全文
posted @ 2008-12-22 10:41 昕友软件开发 阅读(206) 评论(0) 推荐(0) 编辑
摘要:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ChickenAndEgg { class Program { static void Main(string[] args) { Eg... 阅读全文
posted @ 2008-12-19 17:22 昕友软件开发 阅读(219) 评论(0) 推荐(0) 编辑
摘要:participants The classes and/or objects participating in this pattern are: Context (Account) defines the interface of interest to clients maintains an instance of a Con... 阅读全文
posted @ 2008-12-19 17:05 昕友软件开发 阅读(369) 评论(0) 推荐(0) 编辑

欢迎访问我的开源项目:xyIM企业即时通讯
点击右上角即可分享
微信分享提示