Class Diagram - Proxy

Class Diagram Proxy

Let us quickly look into the class diagram of the Proxy Design Pattern

Class Diagram- Class Diagram

Let draw a Class called as Hidden Entity representing the object which is hidden which has a method called as request().

There is an another class called as Proxy which is representing the object which is supposed to act as a proxy.

So what are the prerequisites for any entity to be proxy?

As we know one it should have the same interface as that of the hidden object in this case Hidden Entity. So we come out with a interface called as Subject which will also have a method called as request() and both the Proxy and HiddenENtity will now implement this common interface. We have just ensured that the proxy has the same interface as that of the hidden object.

The second prerequisite is that the proxy should always have the fully qualified address of the HiddenEntity. To ensure this we will make the Proxy Class keep a reference to the HiddenENtity class and lets say the name of this reference is abc.

Now we have ensured that Proxy can now act as a complete proxy.

In this figure

  • The Client is like your teacher in the class room
  • The address space is your classroom
  • The Subject interface is the voice based interface using which the teacher recognizes students
  • Proxy class is representing you giving a proxy.
  • HiddenEntity is your friend who is not present in the classroom.

As the Proxy is available in the client address space. Whenever the client calls the request method of the interface subject the Proxy intercepts the call and the request method of the proxy gets called. In the preprocessing cycle if any preprocessing logic needs to be performed will be performed and then the proxy calls the request method on the HiddenENtity using the reference abc. This is where the logic of the request method of HiddenEntity will be performed, the call comes back to the Proxy… any post processing that needs to be done will be performed in the post processing cycle and then the call will return to the client. To the client it looks as if the HiddenEntity is in the same address space , although it is not ..

This is the simple class diagram of the proxy design pattern.

Hemant Jha
Founder - VPlanSolutions
Researcher, Trainer