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