
设计模式
文章平均质量分 74
nuaazhaofeng
爱生活,爱coding
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
设计模式-享元模式
一、定义享元模式(Flyweight Pattern)是池技术的重要实现方式,其定义如下:Use sharing to support large numbers of fine-grained objects efficiently.(使用共享对象可有效地支持大量的细粒度的对象。)享元模式的定义为我们提出了两个要求:细粒度的对象和共享对象。我们知道分配太多的对象到应用程序中将有损程序的性能,同时还原创 2017-01-03 11:07:49 · 375 阅读 · 0 评论 -
设计模式-组合模式
一、定义组合模式(Composite Pattern)也叫合成模式,有时又叫做部分-整体模式(Part-Whole), 主要是用来描述部分与整体的关系,其定义如下:Compose objects into tree structures to represent part-whole hierarchies.Composite lets clients treat individual object原创 2016-12-28 07:31:14 · 331 阅读 · 0 评论 -
设计模式-观察者模式
一、定义观察者模式(Observer Pattern)也叫做发布订阅模式(Publish/subscribe),它是一个在项 目中经常使用的模式,其定义如下:Define a one-to-many dependency between objects so that when one object changes state,all its dependents are notified and原创 2016-12-28 07:50:51 · 384 阅读 · 0 评论 -
设计模式-门面模式
一、定义门面模式(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 use.(要求一原创 2016-12-29 07:39:41 · 434 阅读 · 0 评论 -
设计模式-备忘录模式
一、定义备忘录模式(Memento Pattern)提供了一种弥补真实世界缺陷的方法,让“后悔药”在程 序的世界中真实可行,其定义如下:Without violating encapsulation,capture and externalize an object’s internal state so that the object can be restored to this state l原创 2016-12-29 07:56:56 · 403 阅读 · 0 评论 -
设计模式-访问者模式
一、定义访问者模式(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 the ele原创 2016-12-29 18:22:18 · 307 阅读 · 0 评论 -
设计模式-状态模式
一、定义定义如下:Allow an object to alter its behavior when its internal state changes.The object will appear to change its class.(当一个对象内在状态改变时允许其改变行为,这个对象看起来像改变了其 类。)状态模式的核心是封装,状态的变更引起了行为的变更,从外部看起来就好像这个对象 对应的原创 2016-12-29 22:51:30 · 267 阅读 · 0 评论 -
设计模式-解释器模式
一、定义解释器模式(Interpreter Pattern)是一种按照规定语法进行解析的方案,在现在项目中使 用较少,其定义如下:Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences原创 2016-12-29 23:08:53 · 360 阅读 · 0 评论 -
设计模式-中介者模式
一、定义中介者模式的定义为: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 i原创 2016-12-20 15:42:17 · 258 阅读 · 0 评论 -
设计模式-命令模式
一、定义命令模式是一个高内聚的模式,其定义为:Encapsulate a request as an object,there by letting you parameterize clients with different requests,queue or log requests,and support undoable operations.(将一个请求封装成一个对象,从而让你使用不同的原创 2016-12-20 16:39:15 · 273 阅读 · 0 评论 -
elastic-job动态添加定时任务
在elastic-job的使用过程中,我们会遇到动态添加定时任务的时候,但是官网上面并没有对这块内容进行说明。按照我的理解以及官网上面elastic-job的框架图,ej的定时任务其实是存储在zookeeper的一个个节点上面,所以通过给zookeeper添加对应的节点即可完成定时任务的添加动作。下面上代码:import java.text.SimpleDateFormat; import java原创 2017-04-26 15:34:09 · 2739 阅读 · 0 评论 -
高性能队列Disruptor的使用
一、什么是 Disruptor从功能上来看,Disruptor 是实现了“队列”的功能,而且是一个有界队列。那么它的应用场景自然就是“生产者-消费者”模型的应用场合了。可以拿 JDK 的 BlockingQueue 做一个简单对比,以便更好地认识 Disruptor 是什么。我们知道 BlockingQueue 是一个 FIFO 队列,生产者(Producer)往队列里发布(publish)一项事件原创 2017-06-08 15:03:00 · 3619 阅读 · 0 评论 -
设计模式-迭代器模式
一、定义迭代器模式(Iterator Pattern)目前已经是一个没落的模式,基本上没人会单独写一个迭代器,除非是产品性质的开发,其定义如下:Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.(它提供一种方法访原创 2016-12-27 22:53:52 · 415 阅读 · 0 评论 -
设计模式-适配器模式
一、定义适配器模式(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.(将一个原创 2016-12-27 22:39:16 · 337 阅读 · 0 评论 -
设计模式-策略模式
一、定义策略模式(Strategy Pattern)是一种比较简单的模式,也叫做政策模式(Policy Pattern)。其定义如下:Define a family of algorithms,encapsulate each one,and make them interchangeable.(定义一组算法,将每个算法都封装起来,并且使它们之间可以互换。)这个定义是非常明确、清晰的,“定义一组算法原创 2016-12-27 21:59:52 · 362 阅读 · 0 评论 -
设计模式-桥梁模式
一、定义桥梁模式(Bridge Pattern)也叫做桥接模式,是一个比较简单的模式,其定义如下: Decouple an abstraction from its implementation so that the two can vary independently.(将抽象和实现解耦,使得两者可以独立地变化。)桥梁模式的重点是在“解耦”上,如何让它们两者解耦是我们要了解的重点,我们先来看 桥原创 2017-01-03 11:31:47 · 458 阅读 · 0 评论 -
设计模式-6大设计原则
一、单一职责原则 Single Responsibility Principle,简称SRP。 单一职责原则的定义是:应该有且仅有一个原因引起类的变更。 二、里氏替换原则 Liskov Substitution Principle,LSP 定义1:如果每一个类型为S的对象o1,都有类型为T的对象o2,使得以T定义的所有程序P在所在的对象o1都代换成o2时,程序P的行为没有发生变化,那么类型S是类型T原创 2016-12-18 17:47:37 · 281 阅读 · 0 评论 -
设计模式-单例模式
一、定义单例模式(Singleton Pattern)是一个比较简单的模式,定义如下:Ensure a class has only one instance, and provide a global point of access to it.(确保某一个类职业一个实例,而且自行实例化并向整个系统提供这个实例)Singleton类称为单例类,通过使用private的构造函数确保了在一个应用中只产原创 2016-12-18 20:02:01 · 263 阅读 · 0 评论 -
设计模式-工厂方法模式
一、定义Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.(定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法使一个类的原创 2016-12-18 21:24:14 · 274 阅读 · 0 评论 -
设计模式-抽象工厂模式
一、定义抽象工厂模式(Abstract Factory Pattern)是一种比较常见的模式,其定义如下:Provide an interface for creating families of related or dependent objects without specifying their concrete classes.(为创建一组相关或相互依赖的对象提供一个接口,而且无需指定他们原创 2016-12-19 11:29:34 · 286 阅读 · 0 评论 -
设计模式-模板方法模式
一、定义模板方法模式(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原创 2016-12-19 13:55:32 · 246 阅读 · 0 评论 -
设计模式-建造者模式
一、定义建造者模式(Builder Pattern)也叫生成器模式,其定义如下:Separate the construction fo a complex object from its representation so that the same comstruction process can create different representations.(将一个复杂对象的构建和它的表示原创 2016-12-19 15:54:29 · 215 阅读 · 0 评论 -
设计模式-代理模式
定义代理模式(Proxy Pattern)是一个使用率非常高的模式,其定义如下:Provide a surrogate or placeholder for another object to control access to it.(为其他对象提供一种代理以控制对这个对象的访问。)通用类图:代理模式也叫委托模式,它是一项基本设计技巧。许多其他的模式,如状态模式、策略模式、访问者模式本质上是在更特原创 2016-12-19 17:23:19 · 267 阅读 · 0 评论 -
设计模式-原型模式
一、定义原型模式(Prototype Pattern)的简单程度仅次于单例模式和迭代器模式。Specify the kinds of objects to create using a prototypical instance, and create new objects by copying the prototype.(用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象。)原型模原创 2016-12-19 22:32:35 · 357 阅读 · 0 评论 -
设计模式-责任链模式
一、定义责任链模式定义如下: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原创 2016-12-27 07:41:49 · 388 阅读 · 0 评论 -
设计模式-装饰模式
一、定义装饰模式(Decorator Pattern)是一种比较常见的模式,其定义如下:Attach additional responsibilities to an object dynamically keeping the same interface.Decorators provide a flexible alternative to subclassing for extending原创 2016-12-27 21:37:10 · 247 阅读 · 0 评论 -
【Canal源码分析】Sink及Store工作过程
一、序列图 二、源码分析 2.1 Sink Sink阶段所做的事情,就是根据一定的规则,对binlog数据进行一定的过滤。我们之前跟踪过parser过程的代码,发现在parser完成后,会把数据放到一个环形队列TransactionBuffer中,也就是这个方法: transactionBuffer.add(entry); 我们具体看下add这个方法。 public...原创 2018-05-25 15:01:13 · 586 阅读 · 0 评论