real proxies?

  • Thread starter Thread starter Nikhil Patel
  • Start date Start date
N

Nikhil Patel

Hi,
I am reading MSDN. I encountered following sentence that I don't
understand. Can somebody please shade some light on it?

"The proxy has a dual nature: it acts as an object of the same class as the
remote object (transparent proxy), and it is a managed object itself."

Thanks...
 
I am reading MSDN. I encountered following sentence that I don't
understand. Can somebody please shade some light on it?

"The proxy has a dual nature: it acts as an object of the same class as the
remote object (transparent proxy), and it is a managed object itself."

I'll explain both sides of the dual nature:
1) The proxy looks just like the class that is proxied. For example if you
proxy a class Foo you would have code like this:

Foo bar = new Foo();
int baz = bar.FooMethod();
baz = bar.FooProperty;

So it behaves just like Foo.

2) However the instance is not actually of type Foo, but a proxy type. This
is because (when using remoting) the actual object is on an other machine
for example(or on the same machine in another application domain). The proxy
sends the requests to the actual Foo class and returns the results the Foo
class gives. I think an example makes in more clear:

class FooProxy {
private Foo actualFoo;
public int FooMethod() {
return actualFoo.FooMethod();
}
}

This is a simplified version of what happens, but I think it serves it's
purpose. What actually happens is that the proxy has a connection to another
class on the remote machine (called stub). It sends a message like
"FooMethod was called", the stub then calls the FooMethod on the remote
instance of Foo. When the method returns the int is sent back by the stub to
the proxy (ie. "FooMethod returned 10").

I hope this description is clear enough.

Herman Eldering
 
Back
Top