随笔分类 -  设计模式

摘要:namespace MultipleMementoPattern { // 联系人 public class ContactPerson { public string Name { get; set; } public string MobileNum { get; set; } } // 发起人 public ... 阅读全文
posted @ 2017-05-31 16:13 小小高 阅读(210) 评论(0) 推荐(0) 编辑
摘要:namespace VistorPattern { // 抽象元素角色 public abstract class Element { public abstract void Accept(IVistor vistor); public abstract void Print(); } // 具体元素A publ... 阅读全文
posted @ 2017-05-31 16:11 小小高 阅读(158) 评论(0) 推荐(0) 编辑
摘要:namespace ChainofResponsibility { // 采购请求 public class PurchaseRequest { // 金额 public double Amount { get; set; } // 产品名字 public string ProductName { get;... 阅读全文
posted @ 2017-05-31 16:10 小小高 阅读(175) 评论(0) 推荐(0) 编辑
摘要:// 客户端调用 class Client { static void Main(string[] args) { // 创建一个菠菜实例并调用模板方法 Spinach spinach = new Spinach(); spinach.CookVegetabel(); ... 阅读全文
posted @ 2017-05-17 18:33 小小高 阅读(138) 评论(0) 推荐(0) 编辑
摘要:// 客户端调用 class Client { static void Main(string[] args) { // 创建一个代理对象并发出请求 Person proxy = new Friend(); proxy.BuyProduct(); Con... 阅读全文
posted @ 2017-05-17 18:33 小小高 阅读(122) 评论(0) 推荐(0) 编辑
摘要:// 教官,负责调用命令对象执行请求 public class Invoke { public Command _command; public Invoke(Command command) { this._command = command; } public void... 阅读全文
posted @ 2017-05-17 18:31 小小高 阅读(90) 评论(0) 推荐(0) 编辑
摘要:代码中存在多个if-else语句的情况下,此时可以考虑使用责任链模式来对代码进行重构。 阅读全文
posted @ 2017-05-17 18:24 小小高 阅读(143) 评论(0) 推荐(0) 编辑
摘要:用来替换if else 阅读全文
posted @ 2017-05-17 17:34 小小高 阅读(147) 评论(0) 推荐(0) 编辑
摘要:namespace StatePatternSample { public class Account { public State State {get;set;} public string Owner { get; set; } public Account(string owner) { ... 阅读全文
posted @ 2017-05-15 17:34 小小高 阅读(160) 评论(0) 推荐(0) 编辑
摘要:namespace MediatorPattern { // 抽象牌友类 public abstract class AbstractCardPartner { public int MoneyCount { get; set; } public AbstractCardPartner() { Mo... 阅读全文
posted @ 2017-05-08 13:29 小小高 阅读(188) 评论(0) 推荐(0) 编辑
摘要:namespace ObserverInNET { class Program { // 委托充当订阅者接口类 public delegate void NotifyEventHandler(object sender); // 抽象订阅号类 public class TenXun { ... 阅读全文
posted @ 2017-05-08 13:18 小小高 阅读(268) 评论(0) 推荐(0) 编辑
摘要:// 抽象聚合类 public interface IListCollection { Iterator GetIterator(); } // 迭代器抽象类 public interface Iterator { bool MoveNext(); Object GetCurrent(); ... 阅读全文
posted @ 2017-05-08 13:05 小小高 阅读(118) 评论(0) 推荐(0) 编辑
摘要:/// /// 客户端调用 /// class Client { static void Main(string[] args) { // 定义外部状态,例如字母的位置等信息 int externalstate = 10; // 初始化享元工厂 ... 阅读全文
posted @ 2017-04-28 10:17 小小高 阅读(199) 评论(0) 推荐(0) 编辑
摘要:在以下情况下可以考虑使用外观模式: 为一个复杂的子系统提供一个简单的接口 提供子系统的独立性 在层次化结构中,可以使用外观模式定义系统中每一层的入口。其中三层架构就是这样的一个例子。 阅读全文
posted @ 2017-04-28 10:08 小小高 阅读(154) 评论(0) 推荐(0) 编辑
摘要:四、组合模式的使用场景 在以下情况下应该考虑使用组合模式: 阅读全文
posted @ 2017-04-28 10:03 小小高 阅读(163) 评论(0) 推荐(0) 编辑
摘要:/// /// 手机抽象类,即装饰者模式中的抽象组件类 /// public abstract class Phone { public abstract void Print(); } /// /// 苹果手机,即装饰着模式中的具体组件类 /// public class ApplePhone:P... 阅读全文
posted @ 2017-04-27 14:38 小小高 阅读(113) 评论(0) 推荐(0) 编辑
摘要:采用桥接模式的客户端调用代码: 使用场景: 三层架构 阅读全文
posted @ 2017-04-27 13:41 小小高 阅读(183) 评论(0) 推荐(0) 编辑
摘要:在以下情况下可以考虑使用适配器模式: 阅读全文
posted @ 2017-04-27 10:55 小小高 阅读(134) 评论(0) 推荐(0) 编辑
摘要:///火影忍者中鸣人的影分身和孙悟空的的变都是原型模式 class Client { static void Main(string[] args) { // 孙悟空 原型 MonkeyKingPrototype prototypeMonkeyKing = new ConcretePrototype(... 阅读全文
posted @ 2017-04-26 15:08 小小高 阅读(147) 评论(0) 推荐(0) 编辑
摘要:using System; using System.Collections.Generic; using System.Linq; using System.Text; /// /// 以组装电脑为例子 /// 每台电脑的组成过程都是一致的,但是使用同样的构建过程可以创建不同的表示(即可以组装成不一样的电脑,配置不一样) /// 组装电脑的这个场景就可以应用建造者模式来设计 /// n... 阅读全文
posted @ 2017-04-26 14:55 小小高 阅读(182) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示