In a word, Java design pattern

Source: Internet
Author: User

Design Patterns

See the title, we do not feel incredible, Java 23 design patterns so ' complex ', then ' difficult to understand ', with a sentence how to say understand? First of all, you crossing do not misunderstand, recently looking back to design patterns, have seen before, but the time is to ' kill the Pig Knife ', is a bottle of ' amnesia medicine ', especially for ' program ape ', some things a week do not see, will ' such as ploughing ', the purpose of this article is to describe a design pattern in a sentence, only to help us remember what each design pattern is for, that's all! This time let me on the design model and deep understanding of a bit, but the water is really too deep, the theory is on the one hand, practice can be a genuine knowledge. Only by the theory link practice, can understand more transparent. Want to more deeply understand the design pattern, there is a way, is to see the spring source code, which is basically all the codes are related to the design pattern (personally prefer spring, excellent framework is actually almost)!

Design Pattern Classification

In general, design patterns fall into three broad categories:

    • Create five types of models: Factory method mode, abstract Factory mode, singleton mode, builder mode, prototype mode.

    • Structure mode, a total of seven kinds: Adapter mode, adorner mode, proxy mode, appearance mode, bridging mode, combined mode, enjoy the meta-mode.

    • There are 11 types of behavioral Patterns: Strategy mode, template method mode, observer mode, iteration sub-mode, responsibility chain mode, Command mode, Memo mode, state mode, visitor mode, mediator mode, interpreter mode.

    • In fact, there are two types: concurrency mode and thread pool mode.

Design pattern Principles
    • Opening and closing principle (Open Close Principle)
    • The principle of substitution on the Richter scale (Liskov Substitution Principle)
    • Dependency reversal principle (dependence inversion Principle)
    • Interface Isolation principle (Interface segregation Principle)
    • Dimitri Law (least known principle) (Demeter Principle)
    • Synthetic multiplexing principles (Composite reuse Principle)

Excerpt from: http://www.cnblogs.com/maowang1991/archive/2013/04/15/3023236.html on the design pattern of classification, this blog post is very good, want to further study the classmate hurriedly to see!

Word Factory mode
  1. Factory mode (Factory method)

    使用‘工厂’统一创建实例,一般使用‘静态工厂方法模式’
  2. Abstract Factory mode (Factory)

    其实也属于‘工厂方法模式’,只是针对不同类使用不同的创造工厂,扩展性更好
  3. Singleton mode (Singleton)

    一个类只能产生一个实例,单例的水很深,可以好好探究下
  4. Builder Mode (creator)

    简单说,就是‘工厂’的‘生产线’,批量生产实例
  5. Prototype mode (PROTOTYPE)

    在原型类的基础上,对类进行深(浅)复制
  6. Adapter Mode (Adapter)

    将原型A 通过适配器B 转换为消费者C 需要的类型,比如:苹果的充电器(A)使用适配器(B)使用中国的线插(C)一样
  7. Decorative mode (Decorator)

    通过装饰器A 为目标对象B 增加一些新的功能,关注点在‘新功能’
  8. Agent mode (proxy)

    通过调用代理A 实现调用目标对象B 的目的
  9. Appearance mode (facade)

    通过组件A 将元件B/C/D 组装起来,实现特定功能,如:机箱将CPU,主板,硬盘等元件组装起来,从而使电脑能够正常运行
  10. Bridging mode (bridge)

    抽象出公共通道A和公共标准B,所有标准B 的实现,都能以相同的方式通过通道A
  11. Combination Mode (Composite)

    学习中...
  12. Enjoy meta mode (Flyweight)

    实现对象共享,共享池技术一般都采用享元模式实现
  13. Policy mode (strategy)

    针对不同策略提供具体实现,根据策略选择相应实现;如:计算器的+-*/,用户选择+,系统会调用对应+的具体实现,扩展到其它场景也一样
  14. Template method Mode

    基类中定义主方法和抽象方法,并且主方法调用抽象方法,子类中具体实现抽象方法并加入相应策略,使所有实现的子类在调用时感觉在使用模板一样(语言很难表达清楚,还是看代码理解的快)
  15. Observer Mode (OBSERVER)

    为目标对象添加一个或多个观察者,并且目标对象在操作时通知所有观察者--我修改了
  16. Iterative sub-pattern (Iterator)

    模拟集合对目标对象进行操作
  17. Responsibility chain model (Chain of Responsibility)

    调用者A,调用对象B,对象B 中有对象C 的引用,于是对象C 被调用,对象C 中有对象D 的引用,于是对象D 被调用...
  18. Command mode

    命令发出者A 发出指令给传递者B,传递者B 将指令给执行者C,A 并不关心C 如何完成任务
  19. Memo Mode (Memento)

    目标对象A 的状态S 保存在备忘对象B 中,辅助类 C保存备忘对象 B,当A 状态改变后,通过备忘对象找回原状态
  20. Status mode (state)

    通过不同状态控制不同行为
  21. Visitor Mode (Visitor)

    通过新增目标对象来实现新的操作,不影响原有操作与行为
  22. Broker Mode (mediator)

    添加中介对象实现目标对象的操作,达到解藕目的
  23. Interpreter mode (interpreter)

    通过解释器A 将目标对象 B进行解释,如:计算解释、正则解释等

Do not write do not know, a sentence to say that the design mode is really too difficult, it is not clear! A lot of possible explanations are not clear, I myself also difficult to understand, follow-up and modification! Or that sentence, remember a word, remember a design pattern, this is the goal, heavy responsibilities!

Come on!!!

In a word, Java design pattern

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.