Created
January 29, 2025 03:52
-
-
Save Mwamitovi/a0c01cf7eaf5335f94ded00ab1fddfe2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// The PricedEntree class referencing that namespace: | |
class PricedEntree extends Entree { | |
public function __construct($name, $ingredients) { | |
parent::__construct($name, $ingredients); | |
foreach ($this->ingredients as $ingredient) { | |
if (! $ingredient instanceof \Meals\Ingredient) { | |
throw new Exception('Elements of $ingredients must be Ingredient objects'); | |
} | |
} | |
} | |
public function getCost() { | |
$cost = 0; | |
foreach ($this->ingredients as $ingredient) { | |
$cost += $ingredient->getCost(); | |
} | |
return $cost; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment