Structural patterns of design patterns

Source: Internet
Author: User

we know that the design patterns are six principles and three models, respectively, can be divided into the creation of the model, the structure of the model, the behavior of the model, including: Adapter mode, decorative mode, bridge mode, combination mode, enjoy the meta-mode, proxy mode, appearance mode. Here, let's talk about the structural pattern.

Adapter Mode (Adapter):

Definition: Convert the interface of a class to another interface that the customer likes, and the adapter mode works with those classes that cannot work together because the interface is incompatible.


Figure:


Understand:

In order to improve the reusability, but the interface and reuse of the environment is not the same, so you need to join the adapter mode, so that the interface can be reused.

Bridging Mode (bridge):

Definition: Separating the part of the abstraction from his implementation, so that they can be changed independently, the implementation refers to the abstract class and his derived classes are used to implement their own objects.


Figure:

Understand:

The above example is very easy to understand, mainly using the principle of synthesis/reuse, priority to use the composition and aggregation of objects can better keep each class is encapsulated, greatly reducing the face of new needs and big changes.


combination Mode (Composite):

Definition: Combine objects into a tree structure to represent "partial-whole", hierarchical, combined patterns that allow users to be consistent with the use of individual objects and composite objects.


Figure:

Understand:

The need to reflect the partial and overall hierarchical relationship, when you like the user can ignore the object and a single object, you can use the combination of all the objects in the structure, can be used in combination mode, combined mode allows users to consistently use the composite structure and a single object.


enjoy meta mode (Flyweight):

Defined:

The use of sharing technology effectively supports a large number of fine-grained objects, to provide application performance, saving the system's repeated creation of object instances of the performance consumption. When there are more instances of an object type in our system, and we require these instances to be categorized, we find that there are very few cases where there are really different classifications. For example, when we use pinyin input method, if we say that each word is an instance of the new object, then the memory instance is too big, this time we can consider the duplicate objects from the creation once, then we can consider the meta-mode.


Figure:


Understand:

The enjoy meta-mode can avoid the overhead of very similar classes and effectively reduce the number of instances that need to be instantiated. If you can move those parameters outside the class instance, pass them in when the method is called.


appearance mode (facade):

Definition: Provides a consistent interface for a set of interfaces in a subsystem that defines a high-level interface that makes the system easier to use.

Figure:

Understand:

Provide a simple interface to reduce their dependency.


In a word, I think I understand the big talk mode very shallow, very shallow .....












Structural patterns of design patterns

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.