设计模式gof
Gangs of Four Design Patterns is the collection of 23 design patterns from the book “Design Patterns: Elements of Reusable Object-Oriented Software”.
四种设计模式的帮派是《设计模式:可重用的面向对象软件的元素》一书中的23种设计模式的集合。

Gangs Of Four Design Patterns Book
四个设计模式书的帮派
This book was first published in 1994 and it’s one of the most popular books to learn design patterns. The book was authored by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. It got nicknamed as Gangs of Four design patterns because of four authors. Furthermore, it got a shorter name as “GoF Design Patterns”.
这本书于1994年首次出版,是学习设计模式的最受欢迎的书籍之一。 该书由Erich Gamma,Richard Helm,Ralph Johnson和John Vlissides撰写。 由于四位作者,它被昵称为“四个设计模式的帮派”。 此外,它的简称为“ GoF设计模式”。
GoF设计模式类型 (GoF Design Pattern Types)
GoF Design Patterns are divided into three categories:
GoF设计模式分为三类:
- Creational: The design patterns that deal with the creation of an object. Creational :涉及对象创建的设计模式。
- Structural: The design patterns in this category deals with the class structure such as Inheritance and Composition. 结构 :此类别中的设计模式涉及类结构,例如继承和组成。
- Behavioral: This type of design patterns provide solution for the better interaction between objects, how to provide lose coupling, and flexibility to extend easily in future. 行为的 :这种类型的设计模式提供了解决方案,以实现对象之间更好的交互,如何提供丢失耦合以及将来轻松扩展的灵活性。
创新设计模式 (Creational Design Patterns)
There are 5 design patterns in the creational design patterns category.
创新设计模式类别中有5个设计模式。
Pattern Name | Description |
---|---|
Singleton | The singleton pattern restricts the initialization of a class to ensure that only one instance of the class can be created. |
Factory | The factory pattern takes out the responsibility of instantiating a object from the class to a Factory class. |
Abstract Factory | Allows us to create a Factory for factory classes. |
Builder | Creating an object step by step and a method to finally get the object instance. |
Prototype | Creating a new object instance from another similar instance and then modify according to our requirements. |
模式名称 | 描述 |
---|---|
辛格尔顿 | 单例模式限制了类的初始化,以确保只能创建该类的一个实例。 |
厂 | 工厂模式承担了从类到工厂类实例化对象的责任。 |
抽象工厂 | 允许我们为工厂类创建工厂。 |
建造者 | 逐步创建对象以及最终获取对象实例的方法。 |
原型 | 从另一个类似的实例创建一个新的对象实例,然后根据我们的要求进行修改。 |
结构设计模式 (Structural Design Patterns)
There are 7 structural design patterns defined in the Gangs of Four design patterns book.
《四大帮派设计模式》一书中定义了7种结构设计模式。
Pattern Name | Description |
---|---|
Adapter | Provides an interface between two unrelated entities so that they can work together. |
Composite | Used when we have to implement a part-whole hierarchy. For example, a diagram made of other pieces such as circle, square, triangle, etc. |
Proxy | Provide a surrogate or placeholder for another object to control access to it. |
Flyweight | Caching and reusing object instances, used with immutable objects. For example, string pool. |
Facade | Creating a wrapper interfaces on top of existing interfaces to help client applications. |
Bridge | The bridge design pattern is used to decouple the interfaces from implementation and hiding the implementation details from the client program. |
Decorator | The decorator design pattern is used to modify the functionality of an object at runtime. |
模式名称 | 描述 |
---|---|
适配器 | 在两个不相关的实体之间提供接口,以便它们可以一起工作。 |
综合 | 在我们必须实现部分整体层次结构时使用。 例如,由其他零件(例如圆形,正方形,三角形等)制成的图表。 |
代理 | 为另一个对象提供代理或占位符,以控制对其的访问。 |
飞行重量 | 缓存和重用与不可变对象一起使用的对象实例。 例如,字符串池。 |
正面 | 在现有接口之上创建包装器接口以帮助客户端应用程序。 |
桥 | 桥接设计模式用于将接口与实现分离,并从客户端程序隐藏实现细节。 |
装饰器 | 装饰器设计模式用于在运行时修改对象的功能。 |
行为设计模式 (Behavioral Design Patterns)
There are 11 behavioral design patterns defined in the GoF design patterns.
GoF设计模式中定义了11种行为设计模式。
Pattern Name | Description |
---|---|
Template Method | used to create a template method stub and defer some of the steps of implementation to the subclasses. |
Mediator | used to provide a centralized communication medium between different objects in a system. |
Chain of Responsibility | used to achieve loose coupling in software design where a request from the client is passed to a chain of objects to process them. |
Observer | useful when you are interested in the state of an object and want to get notified whenever there is any change. |
Strategy | Strategy pattern is used when we have multiple algorithm for a specific task and client decides the actual implementation to be used at runtime. |
Command | Command Pattern is used to implement lose coupling in a request-response model. |
State | State design pattern is used when an Object change it’s behavior based on it’s internal state. |
Visitor | Visitor pattern is used when we have to perform an operation on a group of similar kind of Objects. |
Interpreter | defines a grammatical representation for a language and provides an interpreter to deal with this grammar. |
Iterator | used to provide a standard way to traverse through a group of Objects. |
Memento | The memento design pattern is used when we want to save the state of an object so that we can restore later on. |
模式名称 | 描述 |
---|---|
模板方法 | 用于创建模板方法存根并将某些实现步骤推迟到子类。 |
调解员 | 用于在系统中不同对象之间提供集中式通信介质。 |
责任链 | 用于实现软件设计中的松散耦合,其中将来自客户端的请求传递给对象链以对其进行处理。 |
观察者 | 当您对对象的状态感兴趣并希望在发生任何更改时得到通知时,此功能很有用。 |
战略 | 当我们对一个特定的任务有多种算法并且客户决定在运行时使用的实际实现时,将使用策略模式。 |
命令 | 命令模式用于在请求-响应模型中实现丢失耦合。 |
州 | 当对象根据其内部状态更改其行为时,将使用状态设计模式。 |
游客 | 当我们必须对一组相似类型的对象执行操作时,将使用访问者模式。 |
口译员 | 定义一种语言的语法表示形式,并提供解释器来处理这种语法。 |
迭代器 | 用于提供遍历一组对象的标准方法。 |
纪念 | 当我们要保存对象的状态以便以后可以恢复时,将使用memento设计模式。 |
结论 (Conclusion)
Gangs of Four design patterns lay the foundation of core design patterns in programming. There are many other design patterns built on top of these patterns for specific requirements.
四个设计模式的帮派奠定了编程中核心设计模式的基础。 在这些模式之上还有许多其他设计模式可以满足特定需求。
翻译自: https://www.journaldev.com/31902/gangs-of-four-gof-design-patterns
设计模式gof