Proxy pattern: Difference between revisions

Content deleted Content added
No edit summary
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags
Line 66:
 
=== PHP ===
<sourcesyntaxhighlight lang="php">
<?php
 
Line 134:
$image2->displayImage(); // Loading unnecessary
$image1->displayImage(); // Loading unnecessary
</syntaxhighlight>
</source>
 
The program's output is:
Line 146:
 
=== C# ===
<sourcesyntaxhighlight lang="CSharp">
interface ICar
{
Line 201:
car.DriveCar();
}
</syntaxhighlight>
</source>
Output
Sorry, the driver is too young to drive.
Line 213:
 
=== C++ ===
<sourcesyntaxhighlight lang=Cpp>
#include <iostream>
#include <memory>
Line 253:
car->DriveCar();
}
</syntaxhighlight>
</source>
 
=== Crystal ===
<sourcesyntaxhighlight lang = Ruby>
abstract class AbstractCar
abstract def drive
Line 299:
car = ProxyCar.new(driver)
car.drive
</syntaxhighlight>
</source>
 
Output
Line 306:
 
=== Delphi / Object Pascal ===
<sourcesyntaxhighlight lang=Delphi>
// Proxy Design pattern
unit DesignPattern.Proxy;
Line 404:
 
end.
</syntaxhighlight>
</source>
 
Usage
<sourcesyntaxhighlight lang=Delphi>
program Project1;
{$APPTYPE Console}
Line 416:
TProxyCar.New(TDriver.New(25)).DriveCar;
end.
</syntaxhighlight>
</source>
 
Output
Line 429:
The proxy class <tt>ProxyImage</tt> is running on another system than the real image class itself and can represent the real image <tt>RealImage</tt> over there. The image information is accessed from the disk. Using the proxy pattern, the code of the <tt>ProxyImage</tt> 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.
 
<sourcesyntaxhighlight lang=Java>
interface Image {
public void displayImage();
Line 501:
}
}
</syntaxhighlight>
</source>
 
The program's output is:
Line 513:
 
===Python===
<sourcesyntaxhighlight lang="python">
"""
Proxy pattern example.
Line 560:
car = ProxyCar(driver)
car.drive()
</syntaxhighlight>
</source>
 
===Rust===
<sourcesyntaxhighlight lang="rust">
trait ICar {
fn drive(&self);
Line 624:
}
}
</syntaxhighlight>
</source>
==See also==
* [[Composite pattern]]