mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-28 04:03:02 +02:00
25 lines
569 B
PHP
25 lines
569 B
PHP
<?php
|
|
|
|
namespace DesignPatterns\Structural\Proxy;
|
|
|
|
class BankAccountProxy extends HeavyBankAccount implements BankAccount
|
|
{
|
|
/**
|
|
* @var int
|
|
*/
|
|
private $balance;
|
|
|
|
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;
|
|
}
|
|
}
|