Design Patterns online data integration and understanding-Structural Patterns

Source: Internet
Author: User

Bridge)
The bridge mode is used to solve the problem of multi-dimensional changes of the system. It separates the abstract part from the implementation part so that they can all change independently. (See the understanding of the Bridge Mode)
Structure:

Examples in life:

Composite)

Intent:
Combine objects into a tree structure to represent the "part-whole" hierarchy. The composite mode ensures consistency between the use of a single object and a composite object. [Gof design patterns]
Examples in life:
The best example of the combination mode is the. NET Control tree. For details, refer to Zhang Yi's design path or the. NET control source code.
Structure:

Flyweight)
When you need to create many instances of a class in a thread and the instances of this class are only in different States, you can consider whether different parts of the class can be extracted after being instantiated, to share the remaining parts and reduce memory overhead. This solution is the original mode, which mainly solves the performance problems mentioned above.

Structure:

Proxy)

Structure:

Code:

Using System;

Namespace DoFactory. GangOfFour. Proxy. Structural
{

// MainApp test application

Class MainApp
{
Static void Main ()
{
// Create proxy and request a service
Proxy proxy = new Proxy ();
Proxy. Request ();

// Wait for user
Console. Read ();
}
}

// "Subject"

Abstract class Subject
{
Public abstract void Request ();
}

// "RealSubject"

Class RealSubject: Subject
{
Public override void Request ()
{
Console. WriteLine ("Called RealSubject. Request ()");
}
}

// "Proxy"

Class Proxy: Subject
{
RealSubject realSubject;

Public override void request ()
{
// Use 'Lazy initialization'
If (realsubject = NULL)
{
Realsubject = new realsubject ();
}

Realsubject. Request ();
}
}
}

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.