Content deleted Content added
m →External links: HTTP to HTTPS for SourceForge |
|||
(37 intermediate revisions by 27 users not shown) | |||
Line 1:
{{short description|Software design pattern}}
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>
design pattern is one of the twenty-three well-known
''[[Design Patterns|GoF design patterns]]''
that describe how to solve recurring design problems to design flexible and reusable object-oriented software, that is, objects that are easier to implement, change, test, and reuse.
===What problems can the Proxy design pattern solve?
Source:<ref>{{cite web|title=The Proxy design pattern - Problem, Solution, and Applicability|url=http://w3sdesign.com/?gr=s07&ugr=proble|website=w3sDesign.com| * The access to an object should be controlled.
* Additional functionality should be provided when accessing an object.
Line 20 ⟶ 19:
Define a separate <code>Proxy</code> object that
* can be used as a substitute for another object (<code>Subject</code>), and
* implements additional functionality to control the access to this subject.
This
To act as a substitute for a subject, a proxy must implement the <code>Subject</code> interface. Clients can't tell whether they work with a subject or its proxy.
See also the UML class and sequence diagram below.
Line 33 ⟶ 31:
=== UML class and sequence diagram ===
[[File:w3sDesign Proxy Design Pattern UML.jpg|frame|none|A sample UML class and sequence diagram for the Proxy design pattern.
<ref>{{cite web|title=The Proxy design pattern - Structure and Collaboration|url=http://w3sdesign.com/?gr=s07&ugr=struct|website=w3sDesign.com|
In the above [[Unified Modeling Language|UML]] [[
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
Line 47 ⟶ 45:
=== Class diagram ===
[[File:proxy_pattern_diagram.svg|frame|none
[[File:Proxy pattern in LePUS3.gif|frame|none
== Possible usage scenarios ==
===Remote proxy===
In [[distributed object communication]], a local object represents a remote object (one that belongs to a different address space). The local object is a proxy for the remote object, and method invocation on the local object results in [[remote method invocation]] on the remote object. An example would be an [[Automated teller machine|ATM]] implementation, where the ATM might hold proxy objects for bank information that exists in the remote server.
===Virtual proxy===
Line 62 ⟶ 60:
A protection proxy might be used to control access to a resource based on access rights.
==See also==
* [[Composite pattern]]
Line 640 ⟶ 66:
==References==
{{Reflist
==External links==
{{Wikibooks|Computer Science Design Patterns|Proxy|Proxy implementations in various languages}}
{{Commons category}}
* {{cite web |last1=Geary |first1=David |date=2002-02-22 |df=mdy |url=https://www.infoworld.com/article/2074068/take-control-with-the-proxy-design-pattern.html |title=Take control with the Proxy design pattern |work=[[JavaWorld]] |access-date=2020-07-20}}
* [https://perfectjpattern.sourceforge.net/dp-proxy.html PerfectJPattern Open Source Project], Provides componentized implementation of the Proxy Pattern in Java
* {{webarchive |url=https://web.archive.org/web/20120311202925/http://www.netobjectives.com/PatternRepository/index.php?title=AdapterVersusProxyVersusFacadePatternComparison |title=Adapter vs. Proxy vs. Facade Pattern Comparison}}
* [https://sourcemaking.com/design_patterns/proxy Proxy Design Pattern]
* {{webarchive |url=https://web.archive.org/web/20141019100543/http://patterns.org.pl/proxy.html |title=Proxy pattern C++ implementation example}}
* [https://
{{Design Patterns Patterns}}
|