Proxy mode (Proxy)



 GOF Intent: Provide a proxy for other objects to control access to this object

Role:

1) Abstract subject role (Subject): unified interface

2) Proxy role (Proxy):

Keeping a reference makes the entity accessible to the proxy. If RealSubject and Subject have the same interface, Proxy will refer to Subject.

Provides an interface that is identical to the Subject's interface, so that the proxy can be used in place of the entity.

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

 

3) Real Subject: Defines the specific object represented by the proxy role.   

 

Implementation: slightly

 

scenes to be used:

When the objects we need to use are very complex or take a long time to construct, we can use the proxy mode (Proxy). For example: if building an object is time consuming and computer resource intensive, Proxy allows us to control the situation until we need to use the actual object.

A proxy (Proxy) usually contains the same methods as the object to be used, and once the object is used, these methods will be passed through the proxy (Proxy) to the actual object. 

Some situations where proxy mode (Proxy) can be used:

An object, such as a large image, takes a long time to load.    

A computation that takes a long time to complete and needs to display intermediate results during its computation

 

An object has only limited access rights, proxy mode (Proxy) can verify the user's rights

 

advantage:

(1). Clear responsibilities

The real role is to implement the actual business logic, without caring about other affairs that are not part of this responsibility, and complete a transaction through a later agent, with the result that the programming is concise and clear.

(2). The proxy object can act as an intermediary between the client and the target object, thus playing the role of intermediary and protecting the target object.

 

(3). High scalability

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326795061&siteId=291194637