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 ();
}
}
}