mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-09 16:36:37 +02:00
Refactored example of Proxy pattern
This commit is contained in:
25
Structural/Proxy/HeavyBankAccount.php
Normal file
25
Structural/Proxy/HeavyBankAccount.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Structural\Proxy;
|
||||
|
||||
class HeavyBankAccount implements BankAccount
|
||||
{
|
||||
/**
|
||||
* @var int[]
|
||||
*/
|
||||
private $transactions = [];
|
||||
|
||||
public function deposit(int $amount)
|
||||
{
|
||||
$this->transactions[] = $amount;
|
||||
}
|
||||
|
||||
public function getBalance(): int
|
||||
{
|
||||
// this is the heavy part, imagine all the transactions even from
|
||||
// years and decades ago must be fetched from a database or web service
|
||||
// and the balance must be calculated from it
|
||||
|
||||
return array_sum($this->transactions);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user