Java Classic design pattern

Source: Internet
Author: User

I. Overview

In general, design patterns fall into three broad categories:

(1) Creation mode, a total of five kinds: Factory method mode, abstract Factory mode, singleton mode, builder mode, prototype mode.

(2) Structure mode, a total of seven kinds: Adapter mode, adorner mode, agent mode, appearance mode, bridge mode, combination mode, enjoy the meta-mode.

(3) Behavioral mode, a total of 11 kinds: Strategy mode, template method mode, observer mode, iterative sub-mode, responsibility chain mode, Command mode, Memo mode, state mode, visitor mode, mediator mode, interpreter mode.



The six principles of design pattern

1.Opening and closing principle(Open Close Principle)

The open and closed principle is to say to the expansion opening, to modify the closure. When the program needs to expand, can not modify the original code, to achieve a hot plug effect.

2.principle of substitution on the Richter scale(Liskov Substitution Principle)

Its official description is more abstract, can self-Baidu. In fact, it is understood that: (1) A subclass must have the ability to be greater than or equal to the parent class, the method that the parent class can use, and the subclass to use. (2) The return value is the same. Assuming a parent class method returns a list, the subclass returns a ArrayList, which of course can. If the parent class method returns a ArrayList, the subclass returns a list, which does not speak. Here the subclass's ability to return a value is smaller than the parent class. (3) There is also a case of throwing an exception. Any child class method can declare a subclass that throws a parent class method declaration exception.
You cannot declare an exception that throws a parent class that is not declared.

3.Dependency Reversal Principle(Dependence inversion Principle)

This is the basis of the open and close principle, the specific content: interface-oriented programming, dependent on the abstract and not dependent on the specific.

4.Interface Isolation principle(Interface segregation Principle)

This principle means that using multiple isolated interfaces is better than using a single interface. or a reduction of the coupling between the class meaning, from here we see, in fact, the design pattern is a software design ideas, from the large software architecture, in order to upgrade and maintenance convenience. So there are multiple occurrences: reducing dependency and reducing coupling.

5.Dimitri Law(least known principle) (Demeter Principle)

Why is it called the least known principle, that is to say: an entity should be as small as possible interaction with other entities, so that the system function module is relatively independent.

6.The principle of synthetic multiplexing(Composite reuse Principle)

The principle is to use composition/aggregation as much as possible, rather than using inheritance.

Reference text:

Http://www.importnew.com/18390.html

Java Classic 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.