design patterns are divided into three types: created, structured, and behavioral.
Among the created types are :
Singleton, Singleton mode: guarantees that a class has only one instance and provides a global access point to access it
For example:everywhere, for example, when SERVLET,SPRIGMVC is created, it is a single instance of multithreading.
Abstract Factory, Abstraction Factory: Provides an interface that creates a series of related or interdependent objects without specifying their specific classes.
Factory method, Factory methods: Define an interface for creating objects, let subclasses decide which class to instantiate, and Factory method to defer instantiation of a class to subclasses.
Builder, Build mode: Separates the construction of a complex object from his presentation, allowing the same build process to create different representations.
V. Prototype, prototype mode: Specifies the kind of object created with the prototype instance, and creates a new object by copying the prototypes.
Behavioral types are:
Vi. Iterator, Iterator mode: Provides a way to sequentially access individual elements of an aggregated object without exposing the object's internal representation.
VII. Observer, Observer pattern: Defines a one-to-many dependency between objects, and when an object's state changes, all objects that depend on it are notified of Automatic Updates.
For example , it is said that the JDK uses the most patterns, like mail subscriptions or RSS feeds
Template method: Define the skeleton of an algorithm in an operation, and defer some steps into the subclass, Templatemethod so that subclasses can redefine the algorithm to some specific steps without changing the structure of an algorithm.
commands, Command mode: Encapsulates a request as an object, allowing you to parameterize the customer with different requests, queue requests and log requests, and support revocable operations.
State mode: Allows an object to change his behavior when its internal state changes. The object seems to have changed his class.
XI. strategy, Strategy mode: Define a series of algorithms, encapsulate them one by one, and allow them to replace each other, this mode allows the algorithm to be independent of the customers who use them.
12, China of Responsibility, responsibility chain mode: Enables multiple objects to have the opportunity to process the request, thus avoiding the coupling between the requested communicated and the receiver
13, Mediator, Mediator mode: Encapsulates the object interaction of some columns with a mediation object.
14. Visitor, Visitor mode: represents an operation that acts on elements of an object structure, allowing you to define new actions that act on this element without changing the individual element classes.
XV, interpreter, interpreter mode: Given a language, define a representation of his grammar and define an interpreter that uses that representation to interpret sentences in the language.
16. Memento, Memo mode: captures the internal state of an object without destroying the object, and saves the state outside the object.
structural types are:
17, Composite, combination mode: The object is combined into a tree structure to represent a partial overall relationship, and Composite makes the user consistent with the use of individual objects and composite objects.
18, facade, appearance mode: To provide a consistent interface for a set of interfaces in the subsystem, Fa?ade provides a high-level interface, which makes the subsystem easier to use.
19, Proxy, Agent mode: Provide a proxy for other objects to control access to this object
For example, the classic is reflected in the spring AOP facets and in the IOC container
20, Adapter, adapter mode: To convert a class of interfaces into another interface that the customer wants, the Adapter mode makes it possible for those classes to work together because the interface is incompatible and cannot work together.
The adapter pattern of the objects is the origin of various structural patterns, divided into three types: Class, object, interface adapter mode.
Take a look at the three types of adapter mode scenarios:
Class's adapter pattern: When you want to convert a class to a class that satisfies another new interface , you can use the class's adapter pattern, create a new class, inherit the original class, and implement the new interface.
object's adapter pattern: When you want to convert an object to an object that satisfies another new interface, you can create a wrapper class that holds an instance of the original class, and in the method of the wrapper class, the method that invokes the instance is the line.
Interface Adapter Mode: When you do not want to implement all the methods in an interface, you can create an abstract class wrapper, implement all the methods, we write other classes, when we inherit the abstract class.
For example,the Java IO stream is heavily used
Contrast: The adapter pattern is primarily for the conversion of interfaces, while the decorator pattern focuses on dynamically injecting new functions or behaviors (i.e., so-called responsibilities) into the decorator by combining them.
23, Flyweight, to enjoy the meta-mode: The main purpose is to achieve the sharing of objects, that is, the shared pool, when the system objects in many cases can reduce the cost of memory, usually with the Factory mode use.
For example, database connection pooling is the principle
Six principles of design patterns
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. So a nutshell is: In order to make the program good extensibility, easy to maintain and upgrade. To achieve this, we need to use interfaces and abstract classes, which we will refer to later in the specific design.
2. The principle of substitution on the Richter scale (Liskov Substitution Principle)
One of the fundamental principles of object-oriented design of the Richter substitution principle (Liskov Substitution Principle LSP). The Richter substitution principle says that where any base class can appear, subclasses must be able to appear. LSP is the cornerstone of inheritance reuse, only if the derived class can replace the base class, the function of the Software unit is not affected, the base class can be really reused, and the derived class can also add new behavior on the basis of the base class. The principle of substitution on the Richter scale is a supplement to the principle of "open-closed". The key step in implementing the "open-close" principle is abstraction. The inheritance of the base class and subclass is the concrete implementation of abstraction, so the principle of the substitution of the Richter scale is the specification of the concrete steps to realize the abstraction. --from Baidu Encyclopedia
3. Dependence reversal principle (dependence inversion Principle)
This is the basis of the open and close principle, the specific content: TRUE interface programming, relying on abstraction 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. Synthetic multiplexing principles (Composite reuse Principle)
The principle is to use composition/aggregation as much as possible, rather than using inheritance.
To be continued ~~~~~~~~~~~~~~
Java Design Patterns