June 2017
Intermediate to advanced
394 pages
8h 52m
English
Imagine that we'd now like to add a collection of prices to be persisted to our Product Entity. These prices could represent the different prices the product has borne throughout its lifetime or the product price in different currencies. This could be named HistoricalPrice, as shown below:
class HistoricalProduct extends Product { /** * @var Money[] */ protected $prices; public function __construct( $aProductId, $aName, Money $aPrice, array $somePrices ){ parent::__construct($aProductId, $aName, $aPrice); $this->setPrices($somePrices); } private function setPrices(array $somePrices) { $this->prices = $somePrices; } public function prices() { return $this->prices; }}
HistoricalProduct extends ...