The Source for Java Technology Collaboration


Home | Help | Changes | Index | Search | Go

ProxyPattern

The Proxy pattern is one of the most interesting and most used DesignPatterns. The target of this pattern is to define the proxy object, that act between client and real subject to control access to the real subject and to perform necessary tasks every time the real subject is accessed.

There are different types of proxies (defined in Gang of Four book):

  • Virtual proxies create large expensive objects on demand. Icon viewer demonstrate the usage of the image proxy, that prevents creation of the image object already in constructor. It can answer itself on some client’s queries, such a getWidth() or getHeight(), without loading the image into the memory and it loads the image only if the image is really painted.

  • Remote proxy is the local representative of the real subject in a different address space (e.g. remote object on another host). The client thinks that he talks with the remote object, but there is the proxy between them. The Proxy translates the client’s queries in remote calls, gets the results of the query from remote object and forwards them to the client. One good example of the remote proxies are the stub classes in Java RMI: Calculator RMI Service.

  • Protection proxies grant or deny the client access to the real subject.

  • “Smart references” extend the functionality of the “simple” pointers and perform additional maintenance actions every time the real subject is accessed. They can e.g. count the number of references to the real subject or test, if the real subject is locked to prevent that other client simultaneously change it.



Discussion about ProxyPattern

Topic ProxyPattern . { Edit | Ref-By | Printable | Diffs r3 < r2 < r1 | More }
 XML java.net RSS

Revision r3 - 09 Apr 2005 - 17:04:14 - Main.michael_n