Explanation of 23 Design Patterns in Java

Source: Internet
Author: User
Explanation of 23 Design Patterns in Java

Generally, a design pattern describes a proven feasible solution. These solutions are very common and are the most commonly used mode with a complete definition. The general mode has four basic elements: Pattern name, problem, solution, and effect ).

There are 23 common Java design patterns:

1. Abstract Factory: provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes.

2. 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.

3. Bridge: separates abstract parts from their implementations so that they can all change independently.

4. 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.

5. 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.

6. Command mode: encapsulate a request as an object to parameterize the customer with different requests. Request queuing or request logging are recorded, and supports cancelable operations.

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

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

9. Facade mode: 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.

10. Factory method: defines an interface used to create objects, so that the subclass decides which class to instantiate. Factory method delays the instantiation of a class to its subclass.

11. flyweight: uses the sharing technology to effectively support a large number of fine-grained objects.

12. interpreter mode (Interpreter): defines a language, a syntax expression, and an interpreter that uses the interpreter to represent sentences in the interpreter language.

13. Iteration subpattern (iterator): provides a method to access each element in an aggregate object sequentially without exposing the internal representation of the object.

14. Mediation mode: a mediation object is used to encapsulate a series of object interactions. The intermediary does not require explicit internal representation of each object.

15. 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.

16. Observer mode (observer): defines a one-to-many dependency between objects so that when the state of an object changes, all objects dependent on it are notified and automatically refreshed.

17. Original Model mode (prototype): Use a prototype instance to specify the type of the object to be created, and copy the prototype to create a new object.

18. Proxy mode: provides a proxy for other objects to control access to this object.

19. Singleton: ensure that a class has only one instance and provides a global access point to it.

20. State mode: allows an object to change its behavior when its internal state changes. The object seems to have modified its class.

21. 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.

22. 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.

23. 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.