mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-23 17:22:41 +01:00
28 lines
601 B
PHP
28 lines
601 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Structural\Proxy;
|
|
|
|
class HeavyBankAccount implements BankAccount
|
|
{
|
|
/**
|
|
* @var int[]
|
|
*/
|
|
private array $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);
|
|
}
|
|
}
|