Common Java Design Patterns

Source: Internet
Author: User

There are 23 common design patterns:
Abstract Factory:
Provides an interface for creating a series of related or mutually dependent objects without specifying it
Converts an interface of a class to another interface that the customer wants, so that classes that cannot work together due to incompatibility of the original interface can work together.
The abstract part is separated from its implementation part so that it can be changed independently.
Chain of Responsibility:
To remove the coupling between the request sender and receiver
Multiple objects have the opportunity to process this request. Connect these requests to a chain and pass the request along the chain until an object processes it.
Send a request
Encapsulated as an object, so that you can parameterize the customer with different requests, queue requests or record request logs, and support cancelling operations.
Objects are combined into a tree structure to represent the "part-whole" hierarchy. Composite makes the customer's use of a single object and Composite object consistent.
Add some additional responsibilities to an object. In terms of the extended functions, the Decorator mode is more flexible than the subclass generation method.
For a group of subsystems
The interface provides a consistent interface. The Facade mode defines a high-level interface, making this subsystem easier to use.
Factory Method:
Create an object interface and let the subclass decide which class to instantiate. The factory method delays the instantiation of a class to the subclass.
Use sharing
Technology effectively supports a large number of fine-grained objects.
Given a language, it defines a representation of its syntax and defines an interpreter for interpreting a specific syntax.
Allows a method to access various elements in an aggregate object sequentially without exposing the internal representation of the object.
An intermediary object is used to encapsulate a series of object interactions.
The intermediary does not need to explicitly reference each other, so that the coupling is loose and the interaction between objects can be changed independently.
And save the status outside the object.
Defines a one-to-many dependency between objects, so that an object's status is dependent on its
All objects are notified and refreshed.
Use a prototype instance to specify the type of the object to be created, and copy the prototype to create a new object.
Other objects provide a proxy to control access to this object.
Ensure that a class has only one instance and provides a global point to access it.
Change the behavior of an object when its internal status changes. The object seems to have modified its class.
Define a series of algorithms, encapsulate them, and
They can be replaced with each other to make algorithms independent of customers.
Template Method:
Defines the algorithm skeleton in an operation, and delays the code of the specific implementation of these algorithms to the subclass.
Identifies an operation that acts on each element in an object structure, and defines a new operation that acts on this element without changing the class 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: 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.