Study Notes: a simple comparison of seven structural design modes

Source: Internet
Author: User

The seven types of structural design patterns are as follows:

Adapter Mode
Bridge Mode
Composite Combination Mode
Decorator decoration Mode
Facade appearance Mode
Flyweight meta Mode
Proxy Mode
Comparison:

the adapter mode is mainly used to "reuse some existing classes, but the interfaces are inconsistent with the requirements of the Reuse Environment ", it is useful for Code reuse and class library migration.
the bridge mode is generally used in "two very strong changing dimensions ". The Bridge Mode decouples the inherent binding relationship between abstraction and implementation using the "Composite relationship between objects", so that abstraction and implementation can be changed along their respective maintenance.
the composite mode uses a tree structure to implement a common object container, which converts the "one-to-many" relationship into a "one-to-one" relationship, this allows the customer code to process objects and object containers in a consistent manner, without having to worry about processing a single object or a combined object container. Decoupling the "Customer Code and complex object container structure" is the core idea of the composite mode. After decoupling, the customer code will be connected to pure abstract interfaces (rather than the complex internal implementation of the object container) the dependency occurs, so as to better cope with changes ".
by combining, rather than inheriting, the decorator (decoration) mode enables dynamic extension of object functions at runtime, and supports multiple functions as needed. This avoids the "poor flexibility" and "Multi-subclass Derivative Problems" caused by the independent use of inheritance ".
from the perspective of Program , facade not only simplifies the interface of the entire component system, at the same time, the internal and external customer programs of the component have also achieved a "decoupling" effect to some extent-any changes to the internal subsystem will not affect the changes of the fa c Ade interface. The fa c ade design model focuses more on the entire system from the architectural level, rather than the individual class level. Fa C Ade is often an architectural design model.
object-oriented solves the abstract problem. However, as a program entity running on a machine, we need to consider the cost of objects. The flyweight design pattern mainly solves the problem of the cost of object-oriented, and generally does not touch the abstract problem of object-oriented. Use the sharing technology to effectively support a large number of fine-grained objects.
proxy does not necessarily need to maintain interface consistency. As long as indirect control is implemented, sometimes loss and some transparency are acceptable.
from the interface perspective:

The adapter mode focuses on the conversion interface, and 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 incompatibility of interfaces to work together.
The Bridge Mode focuses on the separation of interfaces (abstractions) and their implementations. It separates the abstract parts from their implementations so that they can all change independently.
The decorator (decoration) mode provides object extension functions while paying attention to stable interfaces. It dynamically adds some additional responsibilities to an object. In terms of extended functions, the decorator mode is more flexible than the subclass generation method.
The appearance mode of fa c Ade focuses on simplified interfaces. It provides a consistent interface for a group of interfaces in the subsystem. The Fa C Ade mode defines a high-level interface, this interface makes this subsystem easier to use.
The composite combination mode simplifies interfaces and converts "one-to-many" relationships into "one-to-one" relationships. Combine objects into a tree structure to represent the "part-whole" hierarchy. Composite makes the customer's use of a single object and composite object consistent.
Proxy mode: provides a proxy for other objects to control access to this object.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/ghj1976/archive/2009/06/12/4262939.aspx

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.