Design Pattern-structural

Source: Internet
Author: User

The structure mode, as its name implies, discusses the structure of classes and objects. It uses an Inheritance Mechanism to combine interfaces or implementations (class structure mode ),

Or you can combine some objects to implement new functions (object structure mode ).

 

There are seven common structural modes:

  • Adapter Mode
  • Composite Combination Mode
  • Facade appearance Mode
  • Decorator decoration Mode
  • Bridge Mode
  • Flyweight meta Mode
  • Proxy mode.

 

First, let's take a look at the seven modes:

Adapter Mode

Solution: The interface required by the new environment is not met by the existing object. In this case, we can add an adapter to the existing object.

To adapt to the new application environment.

 

Example: notebook power adapter

 

Composite Combination Mode

Solved problems:

Solve the decoupling between customer programs and complex object containers. A class of objects with "Container characteristics" -- that is, they act as objects and are containers of other objects, by inheriting the unified interface, we can regard the container object and its sub-objects as the same class object to reduce

Complexity of object usage.

 

Example: company branch management

 

Facade appearance Mode

Solved problems:

The simplified interface separates the call of the client program to the child object from the change of the child object.

 

Example: 10086 Query

 

Decorator decoration Mode

Solved problems:

The object extension function is implemented on the premise of a stable interface, mainly to solve the problem of expanding the number of sub-objects caused by the extension of a large number of functions for the object through inheritance.

 

For example, a painting can be attached directly to a wall, or a frame and glass can be added before being mounted to a wall.

 

Bridge Mode

Solved problems:

Separation interface (abstraction) and its implementation. When a type has two or more changes, the change is isolated by inheriting the interface to reduce the amount of code modified due to the change.

 

Example: electric switch

 

Flyweight meta Mode

The solution is to solve the problem that the system memory overhead is too large due to the large number of identical objects.

 

Example: design different types of websites at the same time.

 

Proxy Mode

Solution: Solve the Problem of directly accessing some objects.

Example: intermediary companies

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.