Skip to content

Instantly share code, notes, and snippets.

@genkovich
Last active April 24, 2021 13:42
Show Gist options
  • Save genkovich/c6fe744344a036591b3fb0933e725a74 to your computer and use it in GitHub Desktop.
Save genkovich/c6fe744344a036591b3fb0933e725a74 to your computer and use it in GitHub Desktop.
<?php
class Customer
{
protected Dollars $account;
public function chargeMoney(Dollars $sum): float
{
$result = $this->account - $sum->getAmount();
if ($result < 0) { // Постусловие
throw new Exception();
}
return $result;
}
}
class VIPCustomer extends Customer
{
public function chargeMoney(Dollars $sum): float
{
$result = $this->account - $sum->getAmount();
if ($sum < 1000) { // Добавлено новое поведение
$result -= 5;
}
// Пропущено постусловие базового класса
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment