Skip to content

Instantly share code, notes, and snippets.

@genkovich
Last active October 10, 2022 10:40
Show Gist options
  • Save genkovich/aab6c78c87bee2289dc2bdda29f59c49 to your computer and use it in GitHub Desktop.
Save genkovich/aab6c78c87bee2289dc2bdda29f59c49 to your computer and use it in GitHub Desktop.
LOD
<?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