设计模式

11 篇文章 0 订阅
3 篇文章 0 订阅
1. Abstract Factory (抽象工厂)

Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

提供一个接口,用于创建相关或从属对象的族,而无需指定它们的具体类。

提供一个创建产品族的接口,其每个子类可以生产一系列相关的产品。
使用频率:* * * * *

2. Builder(建造者)

Separate the construction of a complex object from its representation so that the same construction process can create different representations.

将复杂对象的构造与其表示分离,以便相同的构造过程可以创建不同的表示。

将一个复杂对象分解成多个相对简单的部分,然后根据不同需要分别创建它们,最后构建成该复杂对象。
使用频率:* *

3. Factory Method(工厂方法)

Define an interface for creating an object, but let sub-classes decide which class to instantiate. Factory Method lets a class defer instantiation to sub-classes.

定义一个接口来创建一个对象,但是让子类决定实例化哪个类。工厂方法允许类将实例化推迟到子类。

定义一个用于创建产品的接口,由子类决定生产什么产品。
使用频率:* * * * *

4. Prototype(原型)

Specify the kind of objects to create using a prototypical instance, and create new objects by copying this prototype.

使用原型实例指定要创建的对象的类型,并通过复制此原型来创建新对象。

将一个对象作为原型,通过对其进行复制而克隆出多个和原型类似的新实例。
使用频率:* * *

5. Singleton(单例)

Ensure a class has only one instance and provide a global point of access to it.

确保一个类只有一个实例,并提供对它的全局访问点。

某个类只能生成一个实例,该类提供了一个全局访问点供外部获取该实例,其拓展是有限多例模式。
使用频率:* * * *

6. Adapter(适配器)

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

将一个类的接口转换为客户机期望的另一个接口。Adapter允许由于接口不兼容而无法正常工作的类一起工作。

将一个类的接口转换成客户希望的另外一个接口,使得原本由于接口不兼容而不能一起工作的那些类能一起工作。
使用频率:* * * *

7. Bridge(桥接)

Decouple an abstraction from its implementation so that the two can vary independently.

将抽象与其实现解耦,以便两者可以独立变化。

使用频率:* * *

8. Composite(组合)

Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

将对象组合成树结构以表示部分-整体层次结构。Composite允许客户机统一地处理单个对象和对象的组合。

将对象组合成树状层次结构,使用户对单个对象和组合对象具有一致的访问性。(说白了就是一棵树)
使用频率:* * * *

9. Decorator(装饰)

Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

动态地将附加职责附加到对象。装饰器提供了一种灵活的替代子类化的方法来扩展功能。

动态的给对象增加一些职责,即增加其额外的功能。
使用频率:* * *

10. Facade(外观)

Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.

为子系统中的一组接口提供统一的接口。Façade定义了一个更高级别的接口,使子系统更易于使用。

为多个复杂的子系统提供一个一致的接口,使这些子系统更加容易被访问。
使用频率:* * * * *

11. Flyweight(享元)

Use sharing to support large numbers of fine-grained objects efficiently.

使用共享有效地支持大量细粒度对象。

运用共享技术来有效地支持大量细粒度对象的复用。(将一个共享的属性通过函数参数传递到各个类中)
使用频率:*

12. Proxy(代理)

Provide a surrogate or placeholder for another object to control access to it.

为另一个对象提供代理项或占位符以控制对它的访问。

为某对象提供一种代理以控制对该对象的访问。即客户端通过代理间接地访问该对象,从而限制、增强或修改该对象的一些特性。
代理类C和实际类B继承了同一个接口类A,C中有B的实例,通过调用C实现B的功能。
使用频率:* * * *

13. Chain of Responsibility(责任链)

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 along the chain until an object handles it.

通过给多个对象一个处理请求的机会,避免将请求的发送方与接收方耦合。链接接收对象并沿着链传递请求,直到对象处理它为止。

把请求从链中的一个对象传到下一个对象,直到请求被响应为止。通过这种方式去除对象之间的耦合。
使用频率:* *

14. Command(命令)

Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

将请求封装为对象,从而使您可以参数化具有不同请求的客户端、排队或记录请求,并支持可撤消的操作。

将一个请求封装为一个对象,使发出请求的责任和执行请求的责任分割开。
使用频率:* * * *

15. Interpreter(解释器)

Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

给定一种语言,为它的语法定义一个表示法,同时定义一个使用该表示法来解释该语言中句子的解释器。

提供如何定义语言的文法,以及对语言句子的解释方法,即解释器。
使用频率:*

16. Iterator(迭代器)

Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

提供一种在不暴露底层表示的情况下按顺序访问聚合对象元素的方法。

提供一种方法来顺序访问聚合对象中的一系列数据,而不暴露聚合对象的内部表示。
使用频率:* * * * *

17. Mediator(中介)

Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.

定义一个对象来封装一组对象如何交互。Mediator通过防止对象显式地相互引用来促进松散耦合,并允许您独立地改变它们的交互。

定义一个中介对象来简化原有对象之间的交互关系,降低系统中对象间的耦合度,使原有对象之间不必相互了解。
使用频率:* *

18. Memento(备忘录)

Without violating encapsulation, capture and externalize an object’s internal state so that the object can be restored to this state later.

在不违反封装的情况下,捕获并外部化对象的内部状态,以便稍后可以将对象恢复到该状态。

在不破坏封装性的前提下,获取并保存一个对象的内部状态,以便以后恢复它。
使用频率:*

19. Observer(观察者)

Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

在对象之间定义一个一对多的依赖关系,这样当一个对象改变状态时,它的所有依赖项都会被自动通知和更新。

多个对象间存在一对多关系,当一个对象发生改变时,把这种改变通知给其他多个对象,从而影响其他对象的行为。在属性的setter中调用Notify,可实现自动通知。
使用频率:* * * * *

20. State(状态)

Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.

允许对象在其内部状态更改时更改其行为。对象将显示为更改其类。

允许一个对象在其内部状态发生改变时改变其行为能力。
使用频率:* * *

21. Strategy(策略)

Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

定义一系列算法,封装每一个算法,并使它们可以互换。策略允许算法独立于使用它的客户机而变化。

定义了一系列算法,并将每个算法封装起来,使它们可以相互替换,且算法的改变不会影响使用算法的客户。
使用频率:* * * *

22. Template Method(模板方法)

Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.

在操作中定义算法的框架,将某些步骤推迟到子类。模板方法允许子类在不改变算法结构的情况下重新定义算法的某些步骤。

定义一个操作中的算法骨架,而将算法的一些步骤延迟到子类中,使得子类可以不改变该算法结构的情况下重定义该算法的某些特定步骤。
使用频率:* * *

23. Visitor(访问者)

Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.

表示要在对象结构的元素上执行的操作。Visitor允许您定义一个新的操作,而无需更改它所操作的元素的类。

在不改变集合元素的前提下,为一个集合中的每个元素提供多种访问方式,即每个元素有多个访问者对象访问。
使用频率:*

【原文及例子代码】
https://www.dofactory.com/net/design-patterns

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值