Refactored example of Proxy pattern

This commit is contained in:
Dominik Liebler
2018-06-14 22:17:14 +02:00
parent a494c07255
commit ea85485b85
10 changed files with 197 additions and 413 deletions

View File

@@ -0,0 +1,24 @@
<?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;
}
}