13. Proxy (structured Mode)

Source: Internet
Author: User

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.

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.