Java设计模式及类图

创建型模式

1、简单工厂模式

(Simple Factory Pattern)定义一个工厂类,它可以根据参数的不同返回不同类型的实例,被创建的实例通常具有共同的父类。在这里插入图片描述

2、工厂方法模式

定义一个用于创建对象的接口,但是让其子类决定将哪一个类实例化。工厂方法模式让一个类的实例化延迟到其子类。
Factory Method Pattern:Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
在这里插入图片描述

3、抽象工厂模式

提供一个创建一系列相关或者相互依赖对象的接口,而无需指定他们具体的类。
Abstract Factory Pattern: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
在这里插入图片描述

4、建造者模式

将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。
Builder Pattern: Separate the construction of a complex object from its representation so that the same construction process can create different representations.
在这里插入图片描述

5、原型模式

使用原型实例指定待创建对象的类型,并且通过复制这个原型来创建新的对象
Prototypical Pattern: Specify the kinds of objects to create using a
prototypical instance, and create new objects bu copying prototype.
在这里插入图片描述

6、单例模式

确保一个类只有一个实例,并提供一个全局访问点来访问这个唯一实例。
Singleton Pattern: Ensure a class has only one instance, and provide a global point of access to it.
在这里插入图片描述

结构型模式

1、适配器模式

将一个类的接口转换成客户希望的另一个接口。适配器模式让那些接口不兼容的类可以一起工作。
Adapter Pattern: Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.
在这里插入图片描述

2、桥接模式

将抽象部分和它的实现部分解耦,使得两者都可以独立的变化。
Bridge Pattern: Decouple an abstraction from its implementation so that the two can vary independently.
在这里插入图片描述

3、组合模式

组合多个对象形成树形结构以表示具有部分-整体关系的层次结构。组合模式让客户端可以统一对待单个对象和组合对象。
Composite Pattern: Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
在这里插入图片描述

4、装饰模式

动态的给一个对象增加一些额外的职责。就扩展功能而言,装饰模式提供了一种比使用子类更加灵活的替代方案。
Decorator Pattern: Attach additional responsibilities to an object dynamically. Decorator provide a flexible alternative to subclassing for extending functionality.
在这里插入图片描述

5、外观模式

为子系统中的一组接口提供一个统一的入口。外观模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
Facade Pattern: Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to user.
在这里插入图片描述

6、享元模式

运用共享技术有效地支持大量细粒度对象的复用。
Flyweight Pattern: Use sharing to support large numbers of fine-grained objects efficiently.
在这里插入图片描述

7、代理模式

给某一个对象提供一个代理点或者占位符,并由代理对象来控制对元对象的访问。
Proxy Pattern: Provide a surrogate or placeholder for another object to control access to it.
在这里插入图片描述

行为型模式

1、职责链模式

避免将一个请求的发送者与接收者耦合在一起,让多个对象都有机会处理请求。将接收者请求的对象连接成一条链,并且沿着这条链传递请求,知道有一个对象能够处理它为止。
Chain of Responsibility Pattern: 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.
在这里插入图片描述

2、命令模式

将一个请求封装成一个对象,从而可以用不同的请求对客户进行参数化,对请求排队或者记录请求日志,以及支持可撤销的操作。
Command Pattern: Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
在这里插入图片描述

3、解释器模式

给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子。
Interpreter Pattern: Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
在这里插入图片描述

4、迭代器模式

提供一种方法顺序访问一个聚合对象中的各个元素,而又不用暴露该对象的内部表示。
Iterator Pattern: Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
在这里插入图片描述

5、中介者模式

定义一个对象来封装一系列对象的交互。中介者模式使各对象之间不需要显式地互相引用,从而使其耦合松散,而且而且用户可以独立地改变它们之间的交互。
Mediator Pattern: 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.
在这里插入图片描述

6、备忘录模式

在不破坏封装的前提下捕获一个对象的内部状态,并在该对象之外保存这个状态,这样可以在以后将对象恢复到原先保存的状态。
Memento Pattern: Without violating encapsulation, capture and externalize an object’s internal state so that the object can be restored to this state later.
在这里插入图片描述

7、观察者模式

定义对象之间的一种一对多的依赖关系,使得每当一个对象状态发生改变时其相关依赖对象皆得到通知并被自动更新。
Observer Pattern: Define a one-to-many dependency between objects so that when one object changes state, all dependents are notified and updated automatically.
在这里插入图片描述

8、状态模式

允许一个对象在其内部状态改变时改变它的行为。对象看起来似乎修改了它的类。
State Pattern: Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
在这里插入图片描述

9、策略模式

定义一系列算法,将每一个算法封装起来,并让它们可以相互的替换。策略模式让算法可以独立于使用它的用户而变化。
Strategy Pattern: Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that user it.
在这里插入图片描述

10、模板方法模式

定义一个操作中算法的框架,而将一些步骤延迟到子类中。模板方法模式使得子类可以不改变一个算法的结构即可重新定义该算法的某些特定步骤。
Template Method Pattern: 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.
在这里插入图片描述

11、访问者模式

表示一个作用于某对象结构中的各个元素的操作。访问者模式让用户可以在不改变元素的类的前提下定义作用于这些元素的逐个操作。
Visitor Pattern: 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 elements on which it operates.
在这里插入图片描述

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值