Proxy pattern: Difference between revisions

Content deleted Content added
Monkbot (talk | contribs)
m Task 18 (cosmetic): eval 4 templates: hyphenate params (3×);
m Fix Linter errors.
Line 343:
 
=== Java ===
The following [[Java (programming language)|Java]] example illustrates the "virtual proxy" pattern. The <ttcode>ProxyImage</ttcode> class is used to access a remote method.
 
The example creates first an interface against which the pattern creates the classes. This interface contains only one method to display the image, called <ttcode>displayImage()</ttcode>, that has to be coded by all classes implementing it.
 
The proxy class <ttcode>ProxyImage</ttcode> is running on another system than the real image class itself and can represent the real image <ttcode>RealImage</ttcode> over there. The image information is accessed from the disk. Using the proxy pattern, the code of the <ttcode>ProxyImage</ttcode> avoids multiple loading of the image, accessing it from the other system in a memory-saving manner. The lazy loading demonstrated in this example is not part of the proxy pattern, but is merely an advantage made possible by the use of the proxy.
 
<syntaxhighlight lang=Java>