-
-
Save genkovich/aab6c78c87bee2289dc2bdda29f59c49 to your computer and use it in GitHub Desktop.
LOD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
final class Wallet | |
{ | |
public function __construct(private Money $balance) | |
{ | |
} | |
public function subtract(Money $money): void | |
{ | |
$this->balance = $this->balance->subtract($money); | |
} | |
} | |
final class SomePerson | |
{ | |
public function __construct( | |
private readonly Wallet $wallet, | |
) { | |
} | |
public function getWallet(): Wallet | |
{ | |
return $this->wallet; | |
} | |
} | |
#1 | |
$somePerson = new SomePerson(new Wallet(Money::USD(100))); | |
$somePerson->getWallet()->subtract(Money::USD(25)); | |
final class SomeAnotherPerson | |
{ | |
public function __construct( | |
private readonly Wallet $wallet, | |
) { | |
} | |
public function subtractMoney(Money $money): void | |
{ | |
$this->wallet->subtract($money); | |
} | |
} | |
#2 | |
$someAnotherPerson = new SomeAnotherPerson(new Wallet(Money::USD(100))); | |
$someAnotherPerson->subtractMoney(Money::USD(25)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment