-
-
Save genkovich/c6fe744344a036591b3fb0933e725a74 to your computer and use it in GitHub Desktop.
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 | |
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