23 design patterns-Java

Source: Internet
Author: User

There are 23 common Java design patterns:

Creation Mode

1. Factory method ):

Defines an interface for creating objects, so that the subclass determines which class to instantiate. Factory method delays the instantiation of a class to its subclass.

2. Abstract Factory ):

Provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes.

3. Construction mode (builder ):

Separates the construction of a complex object from its representation so that different representations can be created during the same construction process.

4. Singleton ):

Ensure that a class has only one instance and provides a global access point to it.

5. Original Model mode (prototype ):

Use a prototype instance to specify the object type and copy the prototype to create a new object.

Structural Mode

 1. Adapter mode ):

Converts an interface of a class to another interface that the customer wants. The adapter mode allows classes that cannot work together due to incompatibility of interfaces or classes.

 2. Bridge ):

Separate the abstract part from its implementation part so that they can all change independently.

 3. merging mode (composite ):

Combine objects into a tree structure to represent the "part-whole" hierarchy. It makes the customer's use of a single object and composite object consistent.

 4. decorator ):

Dynamically add some additional responsibilities to an object. As far as the extension function is concerned, it can generate subclass more flexibly.

 5. Facade ):

Provides a consistent interface for a group of interfaces in the subsystem. The facade mode defines a high-level interface, which makes the subsystem easier to use.

 6. flyweight ):

Use the sharing technology to effectively support a large number of fine-grained objects.

 7. Proxy mode ):

Provide a proxy for other objects to control access to this object.

Behavior mode

 1. chain of responsibility ):

To cancel the coupling between the request sender and receiver, multiple objects have the opportunity to process the request. Connect these objects into a chain and pass the request along the chain until an object processes it.

 2. Command mode ):

Encapsulate a request as an object to parameterize the customer with different requests, queue requests or record request logs, and support cancelable operations.

 3. interpreter mode (Interpreter ):

Given a language, it defines a representation of its syntax, and defines an interpreter that uses it to represent sentences in the language of interpretation.

 4. Iteration submodel (iterator ):

Provides a method to access each element in an aggregate object sequentially without exposing the internal representation of the object.

 5. mediator ):

An intermediary object is used to encapsulate a series of object interactions. The intermediary does not require explicit internal representation of each object.

 6. Memento ):

Capture the internal state of an object without compromising encapsulation, and save the state outside the object. In this way, the object can be restored to the Saved state.

 7. Observer mode (observer ):

Defines a one-to-many dependency between objects so that when the status of an object changes, all objects dependent on it are notified and automatically refreshed.

 8. State ):

Allows an object to change its behavior when its internal state changes. The object seems to have modified its class.

 9. Strategy ):

Define a series of algorithms, encapsulate them one by one, and make them replaceable. This mode makes the algorithm changes independent of the customers who use it.

 10. template method ):

Defines the skeleton of an algorithm in an operation, and delays some steps to the subclass. The template method allows the subclass to redefine certain steps of an algorithm without changing the structure of an algorithm.

 11. Visitor mode (visitor ):

Indicates an operation that acts on each element in an object structure. This mode defines new operations on these elements without changing the classes of each element.

 

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.