"Onlookers" design pattern (30)--Summary of structural design patterns (adapters, agents, decorations, appearances, bridges, combinations, and benefits)

Source: Internet
Author: User

Design Pattern Code

Design Pattern Code


1 Adapter Mode in design mode, the adapter pattern (English: Adapter pattern) is sometimes called a wrapper style or wrapper (wrapper). The interface of a class is forwarded to what the user expects. An adaptation makes it possible to work with classes that cannot work together because of incompatible interfaces, by wrapping the class's own interface in an existing class. ----WIKIPEDIA

Personal understanding
Adapter mode: Two inconsistent or not directly used classes or interfaces are compatible through adapter mode so that they can be used in one piece. Adapter mode in the previous project I was used to deal with the incompatible data, the other side of the data and our data format is not exactly the same, including, the type of inconsistency and inconsistent content, type of inconsistency is easier to solve, but inconsistent content such as: the other side of the data there is an ID corresponding to the two values, In our system, an ID only corresponds to a value, so it is obvious that there is no way to use directly, and the other side of the data to be stored, a certain setting before the data into our database, I was the solution is to put the local ID is set to string type, Then through id_**, the id_ identity bit identifies which id the value belongs to and the meaning it represents. In order to achieve this, I used the adapter mode, the data passed by the other side of the package, through the adapter to the encapsulated object into the object we can store locally.
"Onlookers" design mode (11)--Structural type Adapter mode (Adapter pattern)


2 proxy Mode proxy Mode (English: Proxy pattern) is a design pattern in programming.
The so-called proxy refers to a class that can be used as an interface to other things. An interface that a proxy can do anything: A network connection, a large object in memory, a file, or other resource that is expensive or cannot be copied. ----WIKIPEDIA

Personal understanding
Proxy mode is to find another object as a proxy to implement the request for you, the proxy mode is divided into two types, one is the static proxy mode, the other is the dynamic proxy mode, the static proxy mode is the proxy class for it to create an object, the object that needs the proxy class is given to the object in the proxy class. Let the object in the proxy class replace the object of the class that needs the proxy to perform certain tasks. Dynamic proxy mode uses the dynamic agent of JDK, and generates proxy object based on its class loader and its implemented interface, and realizes dynamic proxy through reflection mechanism. "Onlookers" design mode (12)--The structure of the proxy mode (proxy pattern)

3 Decoration ModeThe modified mode is a design pattern that dynamically adds new behavior to a class in the field of object-oriented programming. In terms of functionality, the grooming pattern is more flexible than generating subclasses, which can add functionality to an object rather than to the entire class. ----WIKIPEDIA

Personal understanding

Compared to my understanding of the decorative mode is not very deep, in the project does not know how to use it, perhaps there is no need to decorate the scene of the pattern, my understanding of the decorative mode can be achieved through the decoration mode to expand the function, so I think of the aspect-oriented programming, because I remember that AOP in the implementation of the time, is to enhance the function of the class, can be executed before the method call, after the call, the exception when the occurrence of the time to do the corresponding processing, I would like to be implemented when the pattern is the decoration mode? Here I first keep this question later have time to see the source of the words and then to explore whether the use of this mode. Decoration mode can pass through the constructor to decorate the class instance, the adornment class and the decorated class must have the same interface, guarantees when the adornment class does not carry on the enhancement processing, still can carry on the adornment class to carry on the method which should execute.

"Onlookers" design pattern (13)--Structural pattern of decorative patterns (Decorator pattern)



4 Appearance Mode appearance mode (facade pattern) is a software design pattern commonly used in software engineering, which provides a unified high-level interface for a set of interfaces in a subsystem, making subsystems easier to use. ----WIKIPEDIA
Personal understanding

When there is a messy call relationship in a project, the coupling between classes and classes is too complex, in order to reduce the coupling, we can use a common interface with other classes to be coupled, so as to minimize the external and the system's coupling, while reducing the complexity of the whole system, The exterior mode is the same as a public entrance, which opens the door to the user, leaks some necessary interfaces and makes it easy for the outside world to make calls. In layman's terms, there are several different classes that provide multiple access interfaces, and the façade pattern is to manage these interfaces uniformly.

"Onlookers" design pattern (14)--Structural appearance pattern (facade pattern)



5 Bridge Mode Bridge mode is one of the most complicated patterns in software design mode, which separates objects from their specific behavior and specific characteristics, so that they can change independently of each other. A Thing object is only an abstract concept. such as "Circle", "triangle" is attributed to the abstract "shape", while "Draw Circle", "triangle" is the implementation of the behavior of the "Paint" class, and then called by "shape" paint. ----WIKIPEDIA

Personal understanding
The core of bridge mode is decoupling, abstracting concrete things into general things by abstraction, that is, something with generality, changing the inheritance relationship between two characters into the aggregation relation, which is to change the strong association between them into weak association. Therefore, the so-called decoupling in bridge mode refers to the use of aggregation relationships rather than inheritance relationships between abstractions and implementations of a software system, so that they can vary relatively independently. This is the purpose of bridge mode.
"Onlookers" design pattern (15)--Structural type bridge pattern


6 Combination ModeThe combination mode is also called the composition mode, sometimes called the partial-whole pattern, is mainly used to describe the relationship between the part and the whole, which is defined as: combining objects into a tree structure to represent the "whole and part" hierarchy, which makes the user consistent with the use of individual objects and composite objects. Zen of----Design pattern
Personal understanding
The purpose of combination mode is to combine the whole and part into a tree to represent the whole and part of the hierarchy, so that the user has a consistent interface for the use of a single object and a combined object, that is, the uniform operation of the child objects through the interface. "Onlookers" design pattern (16)--the combination pattern of structure type (Composite pattern)



7 enjoy meta mode enjoy meta mode (English: Flyweight pattern) is a software design pattern. It uses shared objects to minimize memory usage and to share information to as many similar objects as possible, and it is suitable for use in large amounts of memory when a large number of objects are simply duplicated and thus result in unacceptable usage. Usually part of the state in an object can be shared. It is common practice to put them in an external data structure and pass them on to the element when it is needed. ----WIKIPEDIA

Personal understanding
Sharing, memory consumption should consider the sharing of objects, shared objects can reduce the number of objects generated, which can reduce the consumption of memory, when an object and other objects exist in common and the content is consistent, you can extract the common parts to share, so that all of the resulting objects consume memory of the sum will be reduced, This reflects the importance of sharing. "Onlookers" design pattern (17)--structure-type of the Flyweight pattern

"Onlookers" design pattern (30)--Summary of structural design patterns (adapters, agents, decorations, appearances, bridges, combinations, and benefits)

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.