Could someone tell what a proxy pattern is used for? I know a proxy object represents another object.
Joined: Aug 10, 2001
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.
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.