Direct and indirect
People often have a processing method for complex software systems, that is, adding an indirect layer to obtain a more flexible and specific solution for the system.
Motivation)
In an object-oriented system, some objects are required for some reason (for example, the overhead of object creation is large, security control is required for some operations, or external access is required ), direct access may cause a lot of trouble for users or system structures.
How can we manage/control the unique complexity of these objects without losing transparent operation objects? Adding an indirect layer is a common solution in software development.
Intent)
Provides a proxy for other objects to control access to this object.
-- Design Pattern gof
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace proxy
{
Subject # region subject
Interface iemployee
{
Void getsalary ();
Void report ();
Void applyvacation ();
}
# Endregion
Realsubject # region realsubject
Class EMPLOYEE: iemployee
{
Public void getsalary (){}
Public void report (){}
Public void applyvacation (){}
}
# Endregion
Proxy # region proxy
Class employeeproxy: iemployee
{
Public employeeproxy ()
{
// A soap encapsulation for object Creation
}
Public void getsalary ()
{
// A soap encapsulation for Object Access
// Send soap data/call
// If there is a returned value, accept the returned value soap, unpackage, and return the native (raw) C # data
}
Public void report ()
{
}
Public void applyvacation ()
{
}
}
# Endregion
Client # region Client
Class hrsystem
{
Public void process ()
{
Iemployee Employee = new employeeproxy ();
Employee. Report ();
Employee. applyvacation ();
}
}
Class Program
{
Static void main (string [] ARGs)
{
}
}
# Endregion
}
Key Points of proxy Mode
• Adding an indirect layer is a common solution to many complex problems in software systems. In an object-oriented system, using some objects directly brings about many problems. As the proxy object of the indirect layer, it is a common method to solve this problem.
• The implementation methods and implementation granularity of specific proxy design patterns vary greatly, and some may control individual objects in fine granularity, such as copy-on-write technology, some may provide an abstract proxy layer for the component module and proxy the object at the architecture level.
• Proxy does not necessarily require consistency of interfaces. As long as indirect control is implemented, sometimes loss and some transparency are acceptable.