The design pattern of the vegetable--Design Pattern Summary

Source: Internet
Author: User

1. Summary of Design Patterns

Design mode of a total of 23, but commonly used less than 10, the following will be the 23 design pattern collation, as follows:

1) Create pattern, total five kinds: Factory method mode, abstract Factory mode, singleton mode, builder mode, prototype mode.

2) structure mode, a total of seven kinds: Adapter mode, adorner mode, agent mode, appearance mode, bridge mode, combination mode, enjoy the meta-mode.

3) Behavioral mode, total 11 kinds: Strategy mode, template method mode, observer mode, iterator mode, responsibility chain mode, Command mode, Memo mode, state mode, visitor mode, mediator mode, interpreter mode



2. Structural design mode

1) Adapter mode: Transforms the interface of one class into another interface that the customer wants. The adapter mode makes it possible for those classes that would otherwise not work together because of incompatible interfaces to work together.

You want to use a class that already exists, and its interface does not meet the requirements, or you want to create a reusable class that can work with other unrelated classes or classes that are not predictable. You can use the adapter mode at this time, and you can work together by matching.


2) Decoration mode: Dynamically adds some additional responsibilities to an object, and in addition, the decoration mode is more flexible than the generation of sub-classes.

In the face of changes to generate subclasses of the method to deal with, it will inevitably lead to the growth of subclasses. If these subclasses simply add some responsibility to an object, it is more flexible, dynamic and transparent to add responsibilities to a single object, and revoke the appropriate responsibilities when not needed.


3) Proxy mode: Provides a proxy for other objects to control access to this object.

The main difference between a proxy and a skin is that the proxy object represents a single object and the Skin object represents a subsystem, the agent's client object cannot directly access the target object, and the agent provides access control for the individual target object, while the appearance of the client object can directly access the individual objects in the subsystem. However, it is usually provided by the façade object to provide a simplified, common-level invocation interface to the subsystem's component functions. The proxy is a representation of the original object, and the other operations that need to deal with the object are the representations. The adapter does not need to make a fictitious representation, just for the purpose of dealing with specific purposes, the original class to some combination.


4) Appearance mode: Provides a consistent interface for a set of interfaces in a subsystem, and the appearance pattern defines a high-level interface, which makes the subsystem easier to implement.

If two classes do not have to communicate directly with each other, then do not allow these two classes to interact directly. subsystem communication and interdependence in a software should be minimized, and the specific approach is to introduce a visual object that provides a single, simple barrier between subsystems. In fact, you will find that the appearance pattern is much like the pattern of the adapter, but the adapter pattern seems to be finer grained, and the appearance is compatible with a subsystem for compatibility.


5) Bridging mode: Separates the abstract part from its implementation, allowing them to change independently.

Inheritance is a good thing, but often overused, inheritance causes the structure of the class to be too complex, too many relationships, difficult to maintain, and worse to scale poorly. If we find that there are two or more directions in the inheritance system, then we can decouple the changes in the different directions, and change the relationship between the two roles by the combination of the objects, so that the two are able to cope with their own independent changes, so the bridging mode is to find the change and encapsulate it.


6) Combination mode: Combines objects into a tree structure to represent a "partial-whole" hierarchy. The combined mode makes the user consistent with the use of individual objects and composite objects.

Customers can consistently use composite composite structures and individual objects. You can use a composite object wherever you use the base object.


7) Enjoy meta Mode: Use sharing technology to effectively support a large number of fine-grained objects.

Objects make memory consume too much, and if they are a large number of duplicate objects, it is a great waste of resources.




The design pattern of the vegetable--Design Pattern Summary

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.