Summary of design patterns and summary of design patterns

Source: Internet
Author: User

Summary of design patterns and summary of design patterns

Before analyzing each design pattern one by one, I first summarized all the design patterns into three parts: Creation pattern, structure pattern, and behavior pattern.

I. Creation Mode
1. Abstract Factory Model
Provides an interface for creating a series of or related dependent objects without specifying their specific classes.
2. Builder Mode
Separates the construction of a complex object from its representation, so that different representations can be created during the same construction process.
3. Factory method mode
Defines an interface used to create objects so that the subclass determines which class to instantiate. The factory mode delays the instantiation of a class to its subclass.
4. Prototype
Use a prototype instance to specify the type of the created object and copy the prototype to create a new object.
5. Singleton Mode
Ensure that a class has only one instance and provides a global access point to it.
Ii. Structural Mode
6. Adapter Mode
Converts an interface of a class to another interface that the customer wants. The adapter mode allows the classes that cannot work together due to interface incompatibility.
7. Bridging Mode
Separate abstract parts and implementation parts so that they can be changed independently.
8. Combination Mode
The object is combined into a tree structure to represent the 'partial-all' hierarchy. The combination mode ensures consistency between the use of a single object and a composite object.
9. decoration Mode
Dynamically add some additional responsibilities to an object. As for the added function, the decoration mode is more flexible than the subclass generation.
10. Appearance Mode
Provides a consistent interface for a group of interfaces in the subsystem. The appearance mode defines a high-level interface, which makes the subsystem easier to use.
11. metadata sharing
In order to use the sharing technology to effectively support a large number of fine-grained objects.
12. Proxy Mode
Provides a proxy for other objects to control access to this object.
Iii. Behavior Model
13. Observer Mode
Defines a one-to-many dependency between objects. When the status of an object changes, all objects dependent on it are notified and automatically updated.
14. template method mode
Defines the algorithm skeleton of an operation and delays some steps to the subclass. The template method allows the subclass to redefine some specific steps of the Algorithm without changing the structure of an algorithm.
15. Command mode
Encapsulate a request as an object so that you can parameterize the customer with different requests. You can queue requests or record request logs, and support auditable operations.
16. Status Mode
Allows an object to change its behavior when its internal state changes, so that the object seems to have modified its class.
17. Responsibility Chain Model
So that multiple objects have the opportunity to process the request, so as to avoid coupling between the request sender and the receiver. Connect these objects into a chain and pass the request along the chain until an object processes it.
Miscellaneous: MVC includes three types of objects, Model is an application object, and View is its representation on the screen. The Controller defines the response method of the user interface to user input. If MVC is not used, these objects are often mixed in the user interface design, while MVC separates them to improve flexibility and reusability.
18. interpreter Mode
Given a language, it defines a representation of its syntax and an interpreter that uses this representation to interpret sentences in the language.
19. intermediary Mode
An intermediary object is used to encapsulate a series of object interactions. The intermediary makes the objects do not need to be explicitly referenced to each other, so that the coupling is loose and the interaction between them can be changed independently.
20. Visitor Mode
Indicates an operation that acts on each element in an object structure. It allows you to define new operations that act on these elements without changing the classes of each element.
21. Rule Mode
Define a series of algorithms, encapsulate them one by one, and make them replaceable. This mode allows algorithms to change independently of customers who use it.
22. Memorandum Mode
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 previously saved state.
23. iterator Mode
Provides a method to access each element in an aggregate object sequentially without exposing the internal representation of the object.

Zookeeper
What are the design patterns?

There are three types of design patterns: creation, structure, and behavior.
The creation types include:
I. Singleton, Singleton mode: ensure that a class has only one instance and provide a global access point to it.
2. Abstract Factory: provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes.
3. Factory Method: Define an interface used to create objects, and let the subclass decide which class to instantiate. Factory Method delays the instantiation of a class to the subclass.
4. Builder: separates the construction of a complex object from its representation, so that different representations can be created during the same construction process.
5. Prototype: Use a Prototype instance to specify the type of the object to be created, and copy the Prototype to create a new object.
Behavior types:
6. Iterator: provides a method to access each element of an aggregate object sequentially without exposing the internal representation of the object.
7. Observer: Observer mode: defines one-to-many dependencies between objects. When the status of an object changes, all objects dependent on it will be automatically updated by notification.
8. Template Method: defines the skeleton of an algorithm in an operation, and delays some steps to the subclass, templateMethod allows the subclass to redefine a specific step without changing the structure of an algorithm.
9. Command: encapsulate a request as an object so that you can parameterize the customer with different requests, queue requests and record request logs, and supports unrecoverable operations.
10. State: allows an object to change its behavior when its internal State changes. The object seems to have changed its class.
11. Strategy: Define a series of algorithms, encapsulate them one by one, and enable them to replace each other. This mode allows algorithms to be independent of customers who use them.
12. China of Responsibility, Responsibility chain mode: Enables multiple objects to process requests to avoid coupling between the request sender and receiver.
13. Mediator: uses an intermediary object to encapsulate object interaction of some columns.
14. Visitor, Visitor mode: indicates an operation that acts on each element in an object structure. It allows you to define new operations that act on this element without changing the element classes.
15th, Interpreter, Interpreter mode: a language is defined to define a representation of its grammar and an Interpreter. This Interpreter uses this representation to explain sentences in the language.
16. Memento: capture the internal state of an object without interrupting the object, and save the state outside the object.
There are:
17. Composite: Composite combines objects into a tree structure to represent the relationship between parts of the whole. Composite makes the use of a single object and a Composite object consistent.
18. Facade, appearance mode: provides a consistent interface for a group of interfaces in the subsystem. fa? Ade provides a high-level interface, which makes the subsystem easier to use.
19. Proxy: provides a Proxy for other objects to control access to this object.
20. Adapter: the Adapter mode converts a class of interfaces into another interface that the customer wants. The Adapter mode makes those classes unable to work together due to interface incompatibility.
21. Decrator: the Decorator mode dynamically adds some additional responsibilities to an object. In terms of the added functions, the Decorator mode is more flexible than the subclass generation mode.
22. Bridge: link the abstract Part with its implementation... the remaining full text>

Java 23 design patterns, which are commonly used

Factory mode, factory method mode, Singleton mode, Facade mode, Observer mode, and Bridge mode are commonly used, different projects have different design directions, and the design patterns that can be referenced are also different. There is no definite number, but the above models use more.

I looked for other models and listed them.

======================================
Common Java Design Patterns
Creation Mode

1. FACTORY-try to catch up with MM. The chicken wings of McDonald's and the chicken wings of KFC are what MM loves. Although the taste is different, whether you take MM to McDonald's or KFC, just say "four chicken wings" to the waiter. McDonald's and KFC are Factory for chicken wings production.

Factory model: the customer class and the factory class are separated. A consumer needs a product at any time and only requests from the factory. Consumers can accept new products without modification. The disadvantage is that the factory class must be modified when the product is modified. For example, how to create and provide data to clients.

2, BUILDER-MM is the most love to hear is "I love you" this sentence, to see different places of MM, to be able to use their dialect to say this sentence to her oh, I have a multi-language translation machine with a key for each language above. To see MM, I only need to press the corresponding key, it will be able to say "I love you" in the corresponding language, and foreign MM can also easily develop, This is my "I love you" builder. (This must be better than the US military's translation server in Iraq)

Construction mode: separates the internal appearance of a product from the product generation process, so that a building process generates product objects with different internal appearances. The construction mode allows the product's internal appearance to change independently, so that the customer does not have to know the details of the product's internal composition. The construction model enforces a step-by-step construction process.

3. factory method-ask MM to go to McDonald's for a hamburger. Different MM has different tastes. It is annoying to remember every one. I usually use the Factory Method mode, take the MM to the waiter and say "I want a hamburger". What kind of hamburger should I ask the MM to tell the waiter directly.

Factory method mode: the Core factory category is no longer responsible for the creation of all products. Instead, it submits the specific creation work to the subclass to become an abstract factory role, it is only responsible for providing the interface that must be implemented by a specific factory class, without touching the details of which product class should be instantiated.

4. PROTOTYPE-chat with MM via QQ, so I must talk about some affectionate words. I have collected a lot of emotional words, and I just need to copy the words and put them in QQ, this is my prototype. (100 yuan a copy, do you want)

Original Model mode: specify the type of the object to be created by giving a prototype object, and then create more objects of the same type by copying the prototype object. The original model mode allows you to dynamically add or remove product classes. The product class does not need to have any predefined level structure. The original model mode applies to any level structure. The disadvantage is that each class must have a clone method.

5. SINGLETON-I have 6 beautiful wives. My husband is me. I am Sigleton, our husband. All they need to say is "husband, that's me (I had a dream just now. How can this be a good thing)

Singleton mode: Singleton mode ensures that a class has only one instance, and instantiate the instance and provides the singleton mode to the entire system. The Singleton mode can only be used when there is a real "Single Instance" demand.

Structural Mode

6. ADAPTER-I met Sarah, a beautiful girl from Hong Kong at a friend's party. But I can't speak Cantonese, and she can't speak Mandarin. I have to turn to my friend kent for help, as an Adapter between me and Sarah, Sarah and I can talk to each other (I don't know if he will play with me)

Adapter (transformer) mode: converts an interface of a class into another interface that the client expects, so that the two classes that cannot work together due to interface mismatch can work together. The adaptation class can be returned according to the parameters... the remaining full text>

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.