The moose likes OO, Patterns, UML and Refactoring and the fly likes Question on Proxy pattern.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Question on Proxy pattern.." Watch "Question on Proxy pattern.." New topic

Question on Proxy pattern..

Barry Brashear
Ranch Hand

Joined: Jun 05, 2001
Posts: 303
Could someone tell what a proxy pattern is used for? I know a proxy
object represents another object.
Kyle Brown
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
There are two general reasons to use it. One is in a distributed system. When the actual object resides on another machine, and you want to invoke a method on it, the proxy is the local object that receives the method invocation and then marshalls the parameters and sends them across the network, then unmarshalls the result when it comes back. The second general use is in database ORM systems when you have a deeply nested object and you choose to represent a contained object as a proxy that only contains the foreign key -- you would retrieve and instantiate the actual object only when it is referenced through a method call.

Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at for other WebSphere information.
Jelle Klap

Joined: Mar 10, 2008
Posts: 1951

The virtual proxy (in GoF terms) variant is also quite common.
A virtual proxy allows the initialization cost of an 'expensive' (in terms of memoery usage, for example) object to be defered up to the moment it becomes necessary for the actual object to be fully initialized - creation on demand.

Edit: I just realized that Kyle Brown already described this use, though it's not limited to ORM solutions.
[ July 24, 2008: Message edited by: Jelle Klap ]

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
I agree. Here's the link:
subject: Question on Proxy pattern..
It's not a secret anymore!