![](https://img-blog.csdnimg.cn/20210316182827253.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
设计模式
文章平均质量分 57
设计模式学习记录
瓦素老凉
毕业于SCAU,EE专业。懂点嵌入式,目前在点后端技能树。Blog的用途:记录学习笔记和踩过的坑,也是一个地方能找到我。可以的话,还希望能够交一些志同道合的伙伴一起交流。
展开
-
【设计模式之禅】策略模式
策略模式Strategy Pattern定义:Define a family of algorithms,encapsulate each one,and make them interchangeable.定义一组算法 ,把每个算法都封装起来,使他们可以相互切换因为每个算法都是实现于同个接口的,那么他们肯定能相互切换的定义角色:Context 封装角色: 也叫上下文角色。起承上启下的作用,屏蔽高策模块对策略、算法的直接访问。Strategy 抽象策略角色:通常为一个接口。定义了每原创 2021-04-11 22:30:40 · 107 阅读 · 0 评论 -
【设计模式之禅】 责任链模式
责任链模式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 and object.让一个以上的对象都有机会处理请求,原创 2021-04-03 16:55:26 · 86 阅读 · 0 评论 -
【设计模式之禅】 装饰模式
装饰模式Decorator Design Pattern定义:Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.动态地将额外职责附加到对象上,装饰器为子类提供类灵活的代替方法来扩展功能。目的就是需要对类添加功能的时候,不要创建多个子类,而是采用装饰模式原创 2021-04-03 15:55:44 · 122 阅读 · 1 评论 -
【设计模式之禅】命令模式
命令模式Command Pattern定义:Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.将一个请求封装成一个对象,从而,让你使用不同的请求把客户端参数化,对请求排队或记录请求日志,可以提供命令撤销和恢复功能。定义角色:原创 2021-03-21 15:15:24 · 59 阅读 · 0 评论 -
【设计模式之禅】中介者模式
中介者模式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定义一个中介对象封装一组的原创 2021-03-21 12:26:16 · 84 阅读 · 0 评论 -
【设计模式之禅】原型模式
原型模式Prototype Pattern定义:Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype用原型实例指定创建对象的种类,并且通过拷贝这些原型来新的对象原型模式的核心就是clone方法,通过clone方法进行对象的拷贝,而不是new一个对象。在JAVA中提供了Cloneable接口来标识该对象是可以原创 2021-03-21 00:00:56 · 64 阅读 · 0 评论 -
【设计模式之禅】代理模式
代理模式Proxy Pattern定义:Provide a surrogate or placeholder for another object to control access to it.为另外一个对象提供代理或者占位符,以控制对其的访问。代理模式也叫委托模式。目的:代理的目的是在目标对象方法的基础上作增强,这种增强的本质通常就是对目标对象的方法进行拦截和过滤。角色定义:Subject 抽象主题角色 - 一个抽象类活接口Real Subject 具体主题角色 - 被代理原创 2021-03-20 19:10:43 · 93 阅读 · 0 评论 -
【设计模式之禅】建造者模式
建造者模式Builder Pattern定义:Separate the construction of a complex object from its representation so that the same construction process can create different representations将一个复杂对象的构建与它的表示分离,使得相同的构建过程可以创建出不同的表示。角色定义建造者模式下有4个角色:Product 产品类产品类实现了模板方法原创 2021-03-19 18:43:43 · 118 阅读 · 0 评论 -
【设计模式之禅】模板方法模式
模板方法模式Template Method Pattern定义:Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.定义一个操作中的算法框架,将一些步原创 2021-03-19 14:28:02 · 795 阅读 · 0 评论 -
【设计模式之禅】工厂方法模式
工厂方法模式Factory Method Pattern定义:Define an interface for creating an object, but let subclass decide which class to instantiate.Factory Method lets a class defer instantiation to subclass.定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法让一个类实例化延迟到其子类就是说,工厂方法模式通过其子类,原创 2021-03-17 00:29:23 · 96 阅读 · 0 评论 -
【设计模式之禅】单例模式
单例模式Singleton Pattern定义:Ensure a class has only one instance, and provide a global point of access to it.确保一个类只有一个实例(对象),而且自行实例化并且像整个系统提供这个实例通用代码/** * 饿汉式单例 */public class Singleton { private final static Singleton singleton = new Singleton;原创 2021-03-16 23:15:54 · 64 阅读 · 0 评论 -
【设计模式之禅】六大原则的解读
一.六大原则的解读1.单一职责原则Single Responsibility Principle解释:There should never be more than one reason for a class to change.单一职责原则要求一个接口或类只有一个原因引起变化,也就是一个接口或类只有一个职责,他就负责一件事。一个职责就是一个接口。好处:(从上到下还是因果的)类的复杂程度降低,职责清晰可读性提高,不复杂当然好读啦~可维护性提高,简单好读当然好维护啦~风险降低,好原创 2021-03-15 01:53:45 · 131 阅读 · 0 评论