![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
设计模式
cwdben
Do not go gentle into that good night
展开
-
状态模式
状态模式: 当一个对象的内在状态改变时,允许改变其行为。类似状态机。 using System; using System.Collections.Generic; using System.Text; namespace 设计模式 { abstract class State { public abstract void Handle(Context conte...原创 2020-04-09 10:55:02 · 94 阅读 · 0 评论 -
装饰模式
装饰模式: 动态的给一个对象添加一些额外的职责,就增加功能来说,装饰模式比生成子类更为灵活。 using System; using System.Collections.Generic; using System.Text; namespace ConsoleApp1 { abstract class Component { public abstract vo...原创 2020-04-09 10:49:51 · 88 阅读 · 0 评论 -
中介者模式
中介者模式: 用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以控制各个对象的交互。 优点集中控制,缺点也是他,可能导致集中控制的那个中介类代码量编程巨无霸; using System; using System.Collections.Generic; using System.Text; namespace 设计模式 { abstra...原创 2020-04-09 10:47:55 · 93 阅读 · 0 评论 -
职责链模式
职责链模式: 使多个对象都有机会处理器跪求,从而避免请求的发送者和接收者之间的耦合关系。将这个对象连成一条链,并沿这条链传递该请求,知道有一个对象处理它为止。 using System; using System.Collections.Generic; using System.Text; namespace 设计模式 { abstract class Handler { ...原创 2020-04-09 10:46:21 · 70 阅读 · 0 评论 -
原型模式
原型模式:用原型实例指定创建对象的种类,并通过拷贝这些原型创建新的对象。注意下例是浅表复制。 using System; using System.Collections.Generic; using System.Text; namespace 设计模式 { class Person { private string name; public s...原创 2020-04-09 10:45:17 · 79 阅读 · 0 评论 -
享元模式
享元模式: 运用共享技术,让一部分代码被多个类共享。 using System; using System.Collections; using System.Text; namespace 设计模式 { abstract class Flyweight { public abstract void Operation(string extrinsicState)...原创 2020-04-09 08:36:14 · 163 阅读 · 0 评论 -
外观模式
外观模式: 为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。提供简单的接口,减少依赖。子系统可能因为不断地重构变得很复杂和难以修改,交互。编一个清晰的外观模式,和新系统进行交互。 using System; using System.Collections.Generic; using System.Text; namespace 设计模式 ...原创 2020-04-09 08:35:42 · 71 阅读 · 0 评论 -
适配器模式
适配器模式: 将一个类的接口装化成客户希望的另一个接口。使得原本由于接口不兼容的那些类可以一起工作。 using System; using System.Collections.Generic; using System.Text; namespace 设计模式 { class Target { public virtual void Request() ...原创 2020-04-09 08:35:11 · 115 阅读 · 0 评论 -
模板方法模式
模板方法模式: 定义一个操作中算法的骨架,将一些步骤延迟到子类中,模板方法使得子类可以不改变一个算法的结构即可重新定义该算法的某些特定步骤。 通过把不变的行为搬移到超类,去除子类中的重复代码来体现优势。 using System; using System.Collections.Generic; using System.Text; namespace 设计模式 { abstract ...原创 2020-04-09 08:34:29 · 68 阅读 · 0 评论 -
命令模式
命令模式: 讲一个请求封装为一个对象,从而使你可以用不同的请求对客户进行参数化,对请求排队,记录处理,并支持统一操作。 using System; using System.Collections.Generic; using System.Text; namespace 设计模式 { //命令类,规定命令内容Order,命令对象Receiver class Command ...原创 2020-04-08 11:17:23 · 139 阅读 · 0 评论 -
建设者模式
建设者模式 将一个复杂对象的构建与他的表示分离,使得同样的构建过程可以创建不同的表示。创建复杂对象时算法应该独立于该对象的组成部分以及他们的装配方法。 using System; using System.Collections.Generic; using System.Text; namespace 设计模式 { class Product { readonl...原创 2020-04-08 11:13:40 · 172 阅读 · 0 评论 -
简单工厂模式
简单工厂模式: 使用多态,解耦化。仍有一个问题就是在OperationFactory类中,没有完全封装,改进是使用工厂方法模式。 using System; using System.Collections.Generic; using System.Text; namespace ConsoleApp1 { public class Operation { pr...原创 2020-04-08 11:12:32 · 82 阅读 · 0 评论 -
观察者模式
观察者模式: 定义了一种一对多的关系,让多个观察者监听同一个主题对象。这个主题对象在状态更新,发生变化时,会通知其列表中的所有观察者对象,让观察者更新状态,或者做出相应反应。 using System; using System.Collections.Generic; using System.Text; namespace 设计模式 { abstract class Subject ...原创 2020-04-08 11:12:00 · 162 阅读 · 0 评论 -
工厂方法模式
工厂方法模式 定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法使一个类的实例化延迟到其子类。 using System; using System.Collections.Generic; using System.Text; namespace ConsoleApp1 { interface IFactory { Operation CreatOp...原创 2020-04-08 11:11:13 · 86 阅读 · 0 评论 -
访问者模式
访问者模式: 表示一个作用域某对象结构中的个元素的操作。它使你可以在不改变各元素的类的前提下定义作用域这些元素的新操作。 using System; using System.Collections.Generic; using System.Text; namespace 设计模式 { abstract class Visitor { public abstra...原创 2020-04-08 11:10:28 · 90 阅读 · 0 评论 -
代理模式
代理模式 为其他对象提供一种代理以控制对这个对象的访问。 using System; using System.Collections.Generic; using System.Text; namespace ConsoleApp1 { abstract class Subject { public abstract void Request(); } ...原创 2020-04-08 11:09:49 · 80 阅读 · 0 评论 -
抽象工厂模式
抽象工厂模式: 提供一个创建一系列相关或相互依赖对象的接口,而无需指定他们具体的类。 用反射,减少swith的代码(99~112行) using System; using System.Collections.Generic; using System.Text; using System.Reflection; namespace 设计模式 { class User { ...原创 2020-04-08 11:08:59 · 89 阅读 · 0 评论 -
策略模式
策略模式: 定义了算法家族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化不会影响到使用算法的客户. 可以减少算法与算法之间的耦合。 using System; using System.Collections.Generic; using System.Text; namespace ConsoleApp1 { abstract class Strategy { ...原创 2020-04-08 11:08:18 · 95 阅读 · 0 评论 -
备忘录模式
备忘录模式: 在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态,以备对象什么时候需要恢复到这个状态。 using System; using System.Collections.Generic; using System.Text; namespace 设计模式 { class Originator { private string s...原创 2020-04-08 11:05:24 · 146 阅读 · 0 评论