Proxy

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: The Proxy design pattern is used to provide a stand-in for a real class. The proxy implements the same interface as the real class and forwards method calls to it. The GoF...)
 
Line 2: Line 2:
  
 
* A '''remote proxy''' can be used to represent an object which is not contained in the application. For example, an object that is on another networked computer.
 
* A '''remote proxy''' can be used to represent an object which is not contained in the application. For example, an object that is on another networked computer.
* A '''virtual proxy''' is used to implement [[Use lazy initialization pattern|lazy initialisation]]. Useful for creating expensive objects when needed rather than at startup.
+
* A '''virtual proxy''' is used to implement [[Use lazy initialization pattern|lazy initialization]]. Useful for creating expensive objects when needed rather than at startup.
 
* A '''protection proxy''' is used to have greater control over the access rights to the object.
 
* A '''protection proxy''' is used to have greater control over the access rights to the object.
 
* A '''smart reference''' can use a proxy so that when the real object is accessed it can perform additional actions such as creating it on first access and counting references so that it can be deleted when it is no longer referenced (not obvious that this would be important in languages with garbage collection, but there might be additional actions that need to be performed on deletion).
 
* A '''smart reference''' can use a proxy so that when the real object is accessed it can perform additional actions such as creating it on first access and counting references so that it can be deleted when it is no longer referenced (not obvious that this would be important in languages with garbage collection, but there might be additional actions that need to be performed on deletion).
Line 8: Line 8:
 
==Structure==
 
==Structure==
 
Diagram from the GoF:
 
Diagram from the GoF:
 +
 +
[[Image:proxy.png]]
  
 
==Consquences==
 
==Consquences==

Revision as of 22:57, 6 October 2008

The Proxy design pattern is used to provide a stand-in for a real class. The proxy implements the same interface as the real class and forwards method calls to it. The GoF specify four types of proxies that can follow the pattern:

  • A remote proxy can be used to represent an object which is not contained in the application. For example, an object that is on another networked computer.
  • A virtual proxy is used to implement lazy initialization. Useful for creating expensive objects when needed rather than at startup.
  • A protection proxy is used to have greater control over the access rights to the object.
  • A smart reference can use a proxy so that when the real object is accessed it can perform additional actions such as creating it on first access and counting references so that it can be deleted when it is no longer referenced (not obvious that this would be important in languages with garbage collection, but there might be additional actions that need to be performed on deletion).

Structure

Diagram from the GoF:

Proxy.png

Consquences

The proxy design pattern introduces a level of indirection to an object. This has many uses for performance optimization as well as greater flexibility on how references are kept and what kind of objects these references can be made to.

See Also

Personal tools