Content deleted Content added
m Task 18 (cosmetic): eval 4 templates: hyphenate params (3×); |
m →External links: HTTP to HTTPS for SourceForge |
||
(15 intermediate revisions by 14 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>
Line 8 ⟶ 9:
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|access-date=2017-08-12}}</ref> * The access to an object should be controlled.
* Additional functionality should be provided when accessing an object.
Line 18 ⟶ 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 makes it possible to work through a <code>Proxy</code> object to perform additional functionality when accessing a subject
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:
<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]] [[
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 45:
=== Class diagram ===
[[File:proxy_pattern_diagram.svg|frame|none
[[File:Proxy pattern in LePUS3.gif|frame|none
== Possible usage scenarios ==
Line 59:
===Protection proxy===
A protection proxy might be used to control access to a resource based on access rights.
==See also==
Line 691 ⟶ 69:
==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}}
* [
* {{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]
|