Professional Documents
Culture Documents
Using the UML Drawing Tool by implementing the code in Java demonstrate the Proxy
Design Pattern.
The Proxy design pattern makes the clients of a component communicate with a
representative rather than to the component itself. Introducing such a placeholder can serve
many purposes, including enhanced efficiency, easier access and protection from
unauthorized access.
Structure:
Dynamics:
The following diagram shows a typical dynamic scenario of a proxy structure.
While working on its tack the client asks the proxy to carry out a service.
The proxy receives the incoming service request and pre-processes it. This pre-processing
involves actions such as looking up the address of the original, or checking a local cache to
see if the requested information is already available.
If the proxy has to consult the original to fulfill the request, it forwards the request to the
original using the proper communication protocols and security measures.
The original accepts the request and fulfills it. It sends the response back to the proxy.
The proxy receives the response. Before or after transferring it to the client it may carry out
additional post-processing actions such as caching the result, calling the destructor of the
original or releasing a lock on a resource.
Collaboration:
Subject - Interface implemented by the RealSubject and representing its services. The
interface must be implemented by the proxy as well so that the proxy can be used in
any location where the RealSubject can be used.
Proxy
o Maintains a reference that allows the Proxy to access the RealSubject.
o Implements the same interface implemented by the RealSubject so that the
Proxy can be substituted for the RealSubject.
o Controls access to the RealSubject and may be responsible for its creation and
deletion.
o Other responsibilities depend on the kind of proxy.
RealSubject - the real object that the proxy represents.
Problem Statement:
Class Diagram:
AbstractClass
str : String
Client1
main()
proxy Server1
ServerName() getservice()
USE-CASE MODEL:
Proxy
User
Server
ACTIVITY MODEL:
Myapp
prooxy
No
has service
Yes
Server
User
Sequence Diagram:
Client Proxy Server
import java.io.*;
class AbstractClass
{
public String str ;
public AbstractClass()
{
str="";
}
}
class Client1
{
public Proxy m_Proxy;
public static void main(String args[]) throws IOException
{
Proxy m_Proxy1=new Proxy();
System.out.println("\n\n\n 1st time Establishing Connection");
m_Proxy1.ServerName();
System.out.println("\n\n\n 2nd time Retrying for Connection");
m_Proxy1.ServerName();
}
}
Output:
1st time Establishing Connection
Proxy===>
Trying to get the service from server
Server Initializing
Server says Hello.........!