O'Reilly logo

Essential .NET, Volume 1: The Common Language Runtime by Chris Sells, Don Box

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Objects and Context

One particularly nasty problem that occurs when one is building interception plumbing is the need to prevent non-intercepted references to an object from leaking out to the outside world, thus giving callers an opportunity to bypass the services provided by the interceptors. Consider, for example, the following simple class:

public class Bob : MarshalByRefObject {
  public void f() {}
  public Bob GetIt() {
    return this; // danger!
  }
}

In this simple example, the GetIt method returns a reference to the target object. Had a transparent proxy been between the caller and the object, the client would now have two ways to reference the object: one direct and one indirect via the proxy. Now consider the following client code:

 static ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required