Content deleted Content added
Bluelinking 1 books for verifiability.) #IABot (v2.1alpha3 |
→PHP: PHP-FIG PSR |
||
Line 69:
<?php
interface Image
{ public function displayImage();
}
// On System A
class RealImage implements Image
{ private string $filename = null;
/**
Line 81 ⟶ 82:
* @param $filename
*/
public function __construct(string $filename)
{
$this->filename = $filename;
$this->loadImageFromDisk();
Line 89 ⟶ 91:
* Loads the image from the disk
*/
private function loadImageFromDisk()
{
echo "Loading {$this->filename} \r\n";
}
Line 96 ⟶ 99:
* Displays the image
*/
public function displayImage()
{
echo "Displaying {$this->filename} \r\n";
}
}
// On System B
class ProxyImage implements Image
{ private Image $image = null;
private string $filename = null;
Line 111 ⟶ 114:
* @param $filename
*/
public function __construct(string $filename)
{
$this->filename = $filename;
}
Line 118 ⟶ 122:
* Displays the image
*/
public function displayImage()
{
if ($this->image == null) {
$this->image = new RealImage($this->filename);
Line 124 ⟶ 129:
$this->image->displayImage();
}
}
|