Proxy pattern: Difference between revisions

Content deleted Content added
m fixed lint errors – file options; size is ignored when using frame
m v2.05 - Fix errors for CW project (Link equal to linktext - Whitespace characters after heading)
Line 1:
In [[computer programming]], the '''proxy pattern''' is a [[software design pattern]]. A ''proxy'', in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. In short, a proxy is a wrapper or agent object that is being called by the client to access the real serving object behind the scenes. Use of the proxy can simply be [[Forwarding (object-oriented programming)|forwarding]] to the real object, or can provide additional logic. In the proxy, extra functionality can be provided, for example caching when operations on the real object are resource intensive, or checking preconditions before operations on the real object are invoked. For the client, usage of a proxy object is similar to using the real object, because both implement the same interface.
 
==Overview==
The Proxy
<ref name="GoF">{{cite book|author=Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides|title=Design Patterns: Elements of Reusable Object-Oriented Software|year=1994|publisher=Addison Wesley|isbn=0-201-63361-2|pages=[https://archive.org/details/designpatternsel00gamm/page/207 207ff]|url-access=registration|url=https://archive.org/details/designpatternsel00gamm/page/207}}</ref>
Line 33:
<ref>{{cite web|title=The Proxy design pattern - Structure and Collaboration|url=http://w3sdesign.com/?gr=s07&ugr=struct|website=w3sDesign.com|access-date=2017-08-12}}</ref>]]
 
In the above [[Unified Modeling Language|UML]] [[Class diagram|class diagram]],
the <code>Proxy</code> class implements the <code>Subject</code> interface so that it can act as substitute for <code>Subject</code> objects. It maintains a reference (<code>realSubject</code>)
to the substituted object (<code>RealSubject</code>) so that it can forward requests to it