23种设计模式简要说明

时间:2024.4.13

设计模式

创建模式:

1. factory时的一系列初始化工作从构造方法中剥离出来;它们唯一的区别在于在创建类的复杂程度上,抽象工厂指的是将共同部分封装在抽象类中,将不同部分延伸到其子类中去。

2. singleton:确保系统中只有一个实例对象的存在。

3. builder

4. prototype:通过原型实例指定创建对象的类型,并且通过拷贝这些原型来创建新的对象。

结构模式:

1. flyweight:避免大量拥有相同内容的小类的开销。

2. bridge:将抽象和行为划分开来,使得它们各自独立,但又能够动态的结合。(继承抽象接口组合行为接口)。

3. decorator:动态的给一个对象添加一些额外的职责。

4. composite:将对象以树形结构的形式组合起来,已形成部分-到整体的层次结构,使客户端对单个对象和组合对象的使用具有一致性。

5. adapter:将原本两个没有关系的类结合在一起使用(有适配者和被适配者,您可以使用组合模式或者是继承模式)。

6. proxy:为其他对象提供一种代理以控制对这些对象的访问,典型的就是权限控制。

7. facade:为系统中的一组接口提供一个一致的界面。(典型的就是数据库jdbc的操作)。

行为模式:

1. Iterator:Iterator模式可以顺序的访问一个聚集中的元素而不必暴露该聚集的内部情况。

2. Template:定义操作中算法的骨架,将具体操作(一些步骤)的实现延迟到其子类中去。

3. chain of responsibility:通过一系列低耦合的类来试图处理一个request,唯一的共同点就是在它们之间传递request。

4. Memento:通过一个对象拷贝另外一个对象的内容状态,以将该对象恢复到原先保存的状态。

5. mediator:通过一个中介对象来封装一系列对象交互的行为,例如:Android中的Intent。

6. interpreter:定义语言的文法,并创建一个解释器来解释语言中的句子。

7. strategy:定义一系列的算法,并且把这些算法封装成单独的类。

8. state:不同的状态不同的行为。

9. Observer:当一个对象的内存状态发生变化时,Observer可以及时监听到这种变化。

10. Vistor:作用于某个对象群(Arrays或者是Collection)中各个对象的操作,它可以让你

在不改变这些对象本身的情况之下,定义作用于这些对象的新操作。

11. command:来自客户端的请求传入一个对象,我们无需知道该请求激活的动作以及接受

该请求的处理细节。


第二篇:23种设计模式(英语版)


Creational patterns

These patterns have to do with class instantiation. They can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation to get the job done.

Abstract Factory groups object factories that have a common theme.

Builder constructs complex objects by separating construction and representation. Factory Method creates objects without specifying the exact class to create.

Prototype creates objects by cloning an existing object.

Singleton restricts object creation for a class to only one instance.

Structural patterns

These concern class and object composition. They use inheritance to compose interfaces and define ways to compose objects to obtain new functionality.

Adapter allows classes with incompatible interfaces to work together by wrapping its own interface around that of an already existing class.

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

Composite composes zero-or-more similar objects so that they can be manipulated as one object.

Decorator dynamically adds/overrides behaviour in an existing method of an object. Facade provides a simplified interface to a large body of code.

Flyweight reduces the cost of creating and manipulating a large number of similar objects.

Proxy provides a placeholder for another object to control access, reduce cost, and reduce complexity.

Behavioral patterns

Most of these design patterns are specifically concerned with communication between objects.

Chain of responsibility delegates commands to a chain of processing objects. Command creates objects which encapsulate actions and parameters.

Interpreter implements a specialized language.

Iterator accesses the elements of an object sequentially without exposing its underlying representation.

Mediator allows loose coupling between classes by being the only class that has detailed knowledge of their methods.

Memento provides the ability to restore an object to its previous state (undo).

Observer is a publish/subscribe pattern which allows a number of observer objects to see an event.

State allows an object to alter its behavior when its internal state changes.

Strategy allows one of a family of algorithms to be selected on-the-fly at runtime.

Template method defines the skeleton of an algorithm as an abstract class, allowing its subclasses to provide concrete behavior.

Visitor separates an algorithm from an object structure by moving the hierarchy of methods into one object.

Circuit Breaker prevents using a broken external dependency (or internal component) until it comes back online

更多相关推荐:
23种设计模式全解析

23种设计模式全解析分类DesignPattern20xx0624105654864人阅读评论29收藏举报目录一设计模式的分类总体来说设计模式分为三大类创建型模式共五种工厂方法模式抽象工厂模式单例模式建造者模式...

23种设计模式的详解

23种Java设计模式设计模式分两类创建型模式行为型模式一创建型模式1FACTORY追MM少不了请吃饭了麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西虽然口味有所不同但不管你带MM去麦当劳或肯德基只管向服务员说来...

23种设计模式

一设计模式的分类总体来说设计模式分为三大类创建型模式共五种工厂方法模式抽象工厂模式单例模式建造者模式原型模式结构型模式共七种适配器模式装饰器模式代理模式外观模式桥接模式组合模式享元模式行为型模式共十一种策略模式...

23种设计模式

从追MM谈Java的23种设计模式1FACTORY追MM少不了请吃饭了麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西虽然口味有所不同但不管你带MM去麦当劳或肯德基只管向服务员说来四个鸡翅就行了麦当劳和肯德基就是生...

23种设计模式

设计模式主要分三个类型创建型结构型和行为型其中创建型有一Singleton单例模式保证一个类只有一个实例并提供一个访问它的全局访问点二AbstractFactory抽象工厂提供一个创建一系列相关或相互依赖对象的...

23种设计模式

设计模式主要分三个类型创建型结构型和行为型其中创建型有一Singleton单例模式保证一个类只有一个实例并提供一个访问它的全局访问点二AbstractFactory抽象工厂提供一个创建一系列相关或相互依赖对象的...

23种设计模式

新版设计模式手册一创建型模式1单件模式意图保证一个类仅有一个实例并提供一个访问它的全局访问点适用性当类只能有一个实例而且客户可以从一个众所周知的访问点访问它时当这个唯一实例应该是通过子类化可扩展的并且客户应该无...

Java中23种设计模式

Java中23种设计模式目录1设计模式311创建型模式4111工厂方法4112抽象工厂6113建造者模式10114单态模式13115原型模式1512结构型模式17121适配器模式17122桥接模式19123组合...

23种设计模式

创建型模式1FACTORY追MM少不了请吃饭了麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西虽然口味有所不同但不管你带MM去麦当劳或肯德基只管向服务员说来四个鸡翅就行了麦当劳和肯德基就是生产鸡翅的Factory工...

java中的23种设计模式详解

Java中23种设计模式目录1设计模式311创建型模式4111工厂方法4112抽象工厂6113建造者模式10114单态模式13115原型模式1512结构型模式17121适配器模式17122桥接模式19123组合...

Java中最常用的23种设计模式

Java中的23种设计模式1工厂模式客户类和工厂类分开消费者任何时候需要某种产品只需向工厂请求即可消费者无须修改就可以接纳新产品缺点是当产品修改时工厂类也要做相应的修改如如何创建及如何向客户端提供2建造模式将产...

“校本研训模式研究”项目总结报告

精品校本研训模式研究项目总结报告莲山课件6校本研训模式研究项目总结报告1以改进教学管理为目的的校本研训项目1集体备课项目项目内容集体备课项目落实第一步主备教师备课内容预习单教学设计课件配套练习程序集体教研活动两...

23种设计模式总结(21篇)