Agent mode (proxy) C + + implementation

Source: Internet
Author: User

Proxy mode

Although the implementation of decorator is similar to a proxy, the purpose of decorator is different. Decorator adds one or more functions to an object, while the delegate controls access to the object.

Intention:

Provides a proxy for other objects to control access to this object.

Applicability:

Use proxy mode when you need to replace simple pointers with more generic and complex object pointers.

1, the remote agent , that is, for an object in different address space to provide local representation. This can hide the fact that an object exists in a different address space.

2, virtual Agent , is based on the need to create a large cost of objects. It is the real object that takes a long time to store the instantiation.

3, security agent , to control the real object access permissions.

4, Smart guidance , instead of a simple pointer, it performs some additional operations when accessing an object.

Uml:

    

Participants:

Proxy

-Save a reference so that the agent can access the entity. If the interface of Realsubject and subject is the same, proxy references subject.

-Provides an interface with the same interface as the subject, so that proxies can be used instead of entities.

-Controls access to the entity and may be responsible for creating and deleting it.

-Other features depend on the type of proxy.

Subject

-Define the common interface of realsubject and proxy, so that you can use proxy in any place where you use Realsubject.

Realsubject

-Define the entity represented by the proxy.

Code implementation:

Agent mode (proxy) C + + implementation

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.