Proxy Gotchas

As demonstrated in the previous sections, proxies are an extremely powerful tool in the creation of modern apps. However, as with any powerful tool, you can get into trouble if you aren't careful. One of the prime dangers of using proxies is the performance hit they put on your app. When using a proxy, every call to the implementation goes through at least one extra method call. In proxies that perform more complex operations, each call may go through a large amount of code before it contacts the implementation and returns the result of the call. The accumulated performance hit in an app can be significant. A major annoyance of dynamic proxies is that the class has to be designed with the dynamic proxy in mind. If the class does not implement an interface, you can't create a proxy to a class using that interface. Although this is not such a big deal in code over which you have control, in third-party libraries, it can be a pain. As long as you keep the limitations of proxies in mind, judicious use of static and dynamic proxies can provide quite a bit of power to your development.

      
Comments