mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-23 00:01:22 +02:00
24 lines
575 B
PHP
24 lines
575 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Structural\Proxy;
|
|
|
|
class BankAccountProxy extends HeavyBankAccount implements BankAccount
|
|
{
|
|
private ?int $balance = null;
|
|
|
|
public function getBalance(): int
|
|
{
|
|
// because calculating balance is so expensive,
|
|
// the usage of BankAccount::getBalance() is delayed until it really is needed
|
|
// and will not be calculated again for this instance
|
|
|
|
if ($this->balance === null) {
|
|
$this->balance = parent::getBalance();
|
|
}
|
|
|
|
return $this->balance;
|
|
}
|
|
}
|