
java设计模式
luckykapok918
这个作者很懒,什么都没留下…
展开
-
JAVA设计模式(10) —<结构型>桥接模式(Bridge)
1 定义:桥接模式(Bridge)Decouple an abstraction from its implementation so that two can vary independently.(将抽象和实现解耦,使得两者独立地变化。)1.1 通用类图:在桥接模式结构图中包含如下几个角色:●抽象类(Abstraction):用于定义抽象类的接口原创 2015-10-20 16:34:05 · 733 阅读 · 0 评论 -
JAVA设计模式(13) —<行为型>策略模式(strategy)
1定义:策略模式(strategy)Define a family of algorithms, encapsulate each one, and make them interchangeable.(定义一组算法,将每个算法都封装起来,并且使它们之间可以互换)。在策略模式中,我们可以定义一些独立的类来封装不同的算法,每一个类封装一种具体的算法,在这里,每一个封装算法的类我们都可原创 2015-10-21 23:50:39 · 992 阅读 · 0 评论 -
JAVA设计模式(14) —<行为型>模板方法模式(Template Method)
1 定义:模板方法模式(Template Method)Define the skeleton of an algorithm in anoperation, deferring some steps to subclasses. Template Method lets subclassesredefine certain steps of an algorithm without原创 2015-10-22 16:32:23 · 610 阅读 · 0 评论 -
JAVA设计模式(11) —<结构型>组合模式(Composite)
1 定义:组合模式(Composite)Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.(将对象组合成树形结构以原创 2015-10-20 18:55:23 · 770 阅读 · 0 评论 -
JAVA设计模式(12) —<结构型>享元模式(Flyweight)
1 定义:享元模式(Flyweight)Use sharing to support large numbers of fine-grained objects efficiently.(使用共享对象可以有效地支持大量的细粒度的对象。)享元模式要求能够共享的对象必须是细粒度对象。享元对象能做到共享的关键是区分了内部状态(Intrinsic State)和外部状态(Extrins原创 2015-10-21 17:59:02 · 662 阅读 · 0 评论 -
JAVA设计模式(15) —<行为型>观察者模式(Observer)
1 定义:观察者模式(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 updated auto原创 2015-10-22 17:39:20 · 683 阅读 · 0 评论 -
JAVA设计模式(17) —<行为型>责任链模式(Chain of Responsibility)
1 定义:责任链模式(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 th原创 2015-10-23 15:27:31 · 821 阅读 · 0 评论 -
JAVA设计模式(18) —<行为型>命令模式(Command)
1 定义:命令模式(Command),别名为动作(Action)模式或事务(Transaction)模式Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoabl原创 2015-10-23 17:52:14 · 877 阅读 · 0 评论 -
JAVA设计模式(19) —<行为型>备忘录模式(Memento)
1 定义:备忘录模式(Memento)Without violating encapsulation, capture and externalize an object’s internal state so that the object can be restored to this state later. (在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保原创 2015-11-01 21:48:45 · 600 阅读 · 0 评论 -
JAVA设计模式(20) —<行为型>状态模式(State)
1 定义:状态模式(State)Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.(当一个对象内在状态改变时允许其改变行为,这个对象看起来像改变了其类)。1.1 通用类图:一个更易理解的原创 2015-11-01 22:53:37 · 1035 阅读 · 0 评论 -
JAVA设计模式(21) —<行为型>访问者模式(Visitor)
1 定义:访问者模式(Visitor)Represent an operation to be performed on the elements of an object structure. Vistor lets you define a new operation without changing the classes of the elements on which i原创 2015-11-14 15:57:03 · 818 阅读 · 0 评论 -
JAVA设计模式(22) —<行为型>中介者模式(Mediator)
1 定义:中介者模式(Mediator)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 y原创 2015-11-14 17:12:49 · 783 阅读 · 0 评论 -
JAVA设计模式(2) —<创建型>抽象工厂模式(Abstract Factory)
1 定义:抽象工厂模式(Abstract Factory)Provide an interface for creating families of related or dependent objects without specifying their concrete classes.(为创建一组相关或相互依赖的对象提供一个接口,而且无需指定它们的具体类。) 1.1 通用原创 2015-10-15 13:14:09 · 547 阅读 · 0 评论 -
JAVA设计模式(3) —<创建型>单例模式(Singleton)
1 定义:单例模式Ensure a class has only one instance, and provide a global point of access to it.(确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例。)1.1通用类图:图1 单例模式通用类图 Singleton: 负责创建Singleton类自己原创 2015-10-15 15:00:49 · 572 阅读 · 0 评论 -
JAVA设计模式(4) —<创建型>建造者模式(Builder)
1 定义:建造者模式(Builder)Separate the construction of a complex object from its representation so that the same construction process can create different representations.(将一个复杂对象的构建与它的表示分离,使用同样的构建过程可以原创 2015-10-15 17:58:15 · 836 阅读 · 0 评论 -
JAVA设计模式(5) —<创建型>原型模式(Prototype)
1 定义:原型模式(Prototype)Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.(用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象)。1.1 通用类图:原创 2015-10-16 11:32:36 · 531 阅读 · 0 评论 -
JAVA设计模式(6) —<结构型>适配器模式(Adapter)
1 定义:适配器模式(Adapter)Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. (将一原创 2015-10-16 14:59:01 · 468 阅读 · 0 评论 -
JAVA设计模式(9) —<结构型>外观模式(Facade)
1 定义:外观模式(Façade Pattern)Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.(要求一个子系统的外部与其内部的通信必须通原创 2015-10-20 11:33:23 · 751 阅读 · 0 评论 -
设计模式六大原则(3):依赖倒置原则
1. 定义 依赖倒置原则 (Dependence Inversion Principle, DIP )定义:High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon de原创 2015-10-13 15:39:19 · 462 阅读 · 0 评论 -
java设计模式(七)代理模式和java动态代理机制
本文来自:曹胜欢博客专栏。转载请注明出处:http://blog.youkuaiyun.com/csh624366188 代理设计模式 代理是一种常用的设计模式,其目的就是为其他对象提供一个代理以控制对某个对象的访问。代理类负责为委托类预处理消息,过滤消息并转发消息,以及进行消息被委托类执行后的后续处理。 代理模式的作用是:为其他对象提供一种代理以控制对这个对象的访问。在某些情况下,原创 2012-12-10 15:18:38 · 358 阅读 · 0 评论 -
Java设计模式(一)设计模式遵循的七大原则
本文来自:曹胜欢博客专栏。转载请注明出处:http://blog.youkuaiyun.com/csh624366188 最近几年来,人们踊跃的提倡和使用设计模式,其根本原因就是为了实现代码的复用性,增加代码的可维护性。设计模式的实现遵循了一些原则,从而达到代码的复用性及增加可维护性的目的,设计模式对理解面向对象的三大特征有很好的启发,不看设计模式,很难深层地体会到面向对象开发带来的好处原创 2012-12-10 15:18:27 · 382 阅读 · 0 评论 -
java设计模式(二)设计模式分类和三种工厂模式
本文来自:曹胜欢博客专栏。转载请注明出处:http://blog.youkuaiyun.com/csh624366188 设计模式分类 首先先简单说一下设计模式的分类设计模式可以分为三大类,分别是创建型设计模式、行为型设计模式以及结构型设计模式。 创建型的设计模式:单例模式(Singleton)、构建模式(Builder)、原型模式(Prototype)、抽象工厂模式(Abstract F原创 2012-12-10 15:18:29 · 521 阅读 · 0 评论 -
Java设计模式(四)策略模式
本文来自:曹胜欢博客专栏。转载请注明出处:http://blog.youkuaiyun.com/csh624366188 Strategy是属于设计模式中 对象行为型模式,主要是定义一系列的算法,把这些算法一个个封装成单独的类。 定义:策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换。策略模式让算法独立于使用它的客户而独立变化。(原文:The Stra原创 2012-12-10 15:18:31 · 346 阅读 · 0 评论 -
java设计模式(六)观察者模式
本文来自:曹胜欢博客专栏。转载请注明出处:http://blog.youkuaiyun.com/csh624366188 Observer模式是行为模式之一,它的作用是当一个对象的状态发生变化时,能够自动通知其他关联对象,自动刷新对象状态。Observer模式提供给关联对象一种同步通信的手段,使某个对象与依赖它的其他对象之间保持状态同步。《设计模式》一书对Obser原创 2012-12-10 15:18:36 · 591 阅读 · 0 评论 -
java设计模式(八)状态模式
本文来自:曹胜欢博客专栏。转载请注明出处:http://blog.youkuaiyun.com/csh624366188 状态模式:允许对象在内部状态改变时改变它的行为,对象看起来好像修改了它的类。看起来,状态模式好像是神通广大很厉害似的——居然能够“修改自身的类”!下面让我们一起来看一下他的厉害吧! 适用场景: 状态模式主要解决的是当控制一个对象状态装换的条件表达式过于复杂时原创 2012-12-10 15:18:40 · 396 阅读 · 0 评论 -
http://zz563143188.iteye.com/blog/1847029
http://zz563143188.iteye.com/blog/1847029转载 2014-05-07 14:36:35 · 919 阅读 · 0 评论 -
JAVA设计模式(7) —<结构型>装饰模式(Decorator)
1 定义:装饰模式(Decorator)Attach additional responsibilities to an object dynamically keeping the same interface. Decorators provide a flexible alternative to subclassing for extending functionality原创 2015-10-16 18:09:12 · 757 阅读 · 0 评论 -
JAVA设计模式(1) —<创建型>工厂方法模式(Factory Method)
1 定义:工厂方法模式(Factory Method)Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.(定义一个用创原创 2015-10-14 18:08:42 · 596 阅读 · 0 评论 -
JAVA设计模式(16) —<行为型>迭代子模式(Iterator)
1 定义:迭代子模式(Iterator)Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.(它提供一种方法访问一个容器对象中各个元素,而又不暴露该对象的内部细节。)此模式是一个没落的模式,基原创 2015-10-23 14:36:20 · 961 阅读 · 0 评论 -
设计模式六大原则(4):接口隔离原则
1.定义接口隔离原则:(Interface Segregation Principle, ISP)定义1:Clients should not be forced to depend upon interfaces that they don't use.(客户端不应该依赖它不需要的接口)。定义2:The dependcy of one class to another o原创 2015-10-13 16:08:40 · 550 阅读 · 0 评论 -
设计模式六大原则(6):开闭原则
1.定义开闭原则:Open Closed Principle, OCP定义:Software entities like classes, modules and functions should be open for extension but closed for modifications.(一个软件实体如类,模块和函数应该对扩展开放,对修改关闭。)2.理解原创 2015-10-14 11:12:28 · 542 阅读 · 0 评论 -
设计模式六大原则(2):里氏替换原则
1. 定义 里氏替代原则,(Liskov Substitution Principle, LSP ) : 肯定有不少人跟我刚看到这项原则的时候一样,对这个原则的名字充满疑惑。其实原因就是这项原则最早是在1988年,由麻省理工学院的一位姓里的女士(Barbara Liskov)提出来的。 定义1:If for each object o1 of type S原创 2015-10-13 14:52:54 · 759 阅读 · 0 评论 -
设计模式六大原则(5):迪米特法则(最少知道原则)
1.定义迪米特法则:Law of Demeter, LoD),也称最少知道原则(Least Knowledge Principle, LKP)定义:Only talk to your immedate friends.(只与直接的朋友通信)。一个对象应该对其他对象有最少的了解。(通俗地讲,一个类应该对自己需要耦合或调用的类知道得最少)2.理解:2.1 只和直原创 2015-10-13 17:29:56 · 1083 阅读 · 0 评论 -
设计模式六大原则(1):单一职责原则
单一职责原则,(Single Responsibility Principle).1. 定义There should never be more than one reason for a class to change,应该有且仅有一个原因引起类的变更。职责:业务逻辑,或者对象能够承担的责任,并以某种行为方式来执行。2.理解原创 2015-10-13 10:54:28 · 595 阅读 · 0 评论 -
JAVA设计模式(23) —<行为型>解释器模式(Interpreter)
1 定义:解释器模式(Interpreter)Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.(给定一门语言,定义它的方法的一种原创 2015-11-14 23:30:29 · 788 阅读 · 0 评论 -
Java设计模式概述
23种JAVA设计模式原创 2015-10-10 17:41:38 · 798 阅读 · 0 评论 -
JAVA设计模式(8) —<结构型>代理模式(Proxy)
1 定义:代理模式(Proxy)provide a surrogate or placeholder for another object to control access to it.(为其他对象提供一种代理以控制对这个对象的访问)。1.1 通用类图: 代理模式也叫做委托模式,它是一项基本设计技巧。许多其它的模式,如状态模式、策略模式原创 2015-10-19 18:07:10 · 798 阅读 · 0 评论