Reputation: 89
I look the Proxy Pattern in the Wikipedia site : http://en.wikipedia.org/wiki/Proxy_pattern
I understand the program in one computer.
But i ask me questions about the realization in 2 computers.
in reality, in "real life", i suppose that :
1) the interface Subject is duplicated with the same name, in the client (computer A) and in the server (computer B) => am i right ?
2) the object of class Proxy is in the client (computer A)
3) the object of classe RealSubject is in the server (computer B)
4) in the constructor of class Proxy, an instance of RealSubject is created => am i right ?
In the point 4, if i am right, how is it possible to instantiate in a computer A, a class located in a computer B ?
How do you do for example if class B is a Web Service ?
I thank you in advance.
Upvotes: 0
Views: 1123
Reputation: 1195
1) the interface Subject is duplicated with the same name, in the client (computer A) and in the server (computer B) => am i right ? Yes, almost always.
2) the object of class Proxy is in the client (computer A) Yes
3) the object of class RealSubject is in the server (computer B) Yes
4) in the constructor of class Proxy, an instance of RealSubject is created => am i right ? In the constructor or by any other means, maybe the the RealSubject is already created and all you have to do is get a reference to it.
"The [...] the proxy, can add additional functionality to the object of interest without changing the object's code." from Wikipedia.
For calling a Web Service, you simple have a Web Service Proxy, which will encapsulate the call to the WS.
Something like:
class WebServiceProxy {
private WebService ws;
public doWSAction() {
// Here you make the call to the actual web service: setup parameters, check security etc, whatever you need .
...
// then you call the actual web service:
ws.doWSAction()
}
}
So someone who needs the web service will use only your local class, and will not have to do all the things related to the call you are doing in your method.
Upvotes: 2