class ShopProduct { private $title; private $producerMainName; private $producerFirstName; protected $price; function __construct($title, $firstName, $mainName, $price) { $this->title = $title; $this->producerMainName = $mainName; $this->producerFirstName = $firstName; $this->price = $price; } public function getPrice () { return $this->price; } public function getProducerMainName() { return $this->producerMainName; } public function getProducerFirstName() { return $this->producerFirstName; } public function setDiscount( $num ) { $this->discount=$num; } public function getDiscount() { return $this->discount; } public function getTitle() { return $this->title; } public function getProducer() { return "{$this->producerFirstName} {$this->producerMainName}"; } function getSummaryLine() { $base = "{$this->title} ({$this->producerMainName}, {$this->producerFirstName})"; return $base; } } class CDProduct extends ShopProduct { private $playLength = 0; function __construct ($title, $firstName, $mainName, $price, $playLength) { parent::__construct($title, $firstName, $mainName, $price); $this->playLength = $playLength; } function getPlayLength() { return $this->playLength; } function getSummaryLine() { $base = parent::getSummaryLine().": Продолжительность - {$this->playLength}"; return $base; } } class BookProduct extends ShopProduct { private $numPages = 0; function __construct ($title, $firstName, $mainName, $price, $numPages) { parent::__construct($title, $firstName, $mainName, $price); $this->numPages = $numPages; } function getNumberOfPages() { return $this->numPages; } function getSummaryLine() { $base = parent::getSummaryLine().": {$this->numPages} стр."; return $base; } } class ShopProductWriter { private $products = array(); public function addProduct(ShopProduct $shopProduct) { $this->products[] = $shopProduct; } public function write() { $str = ""; foreach ($this->products as $product) { $str .= "{$product->getTitle()}: {$product->getProducer()}; {$product->getPrice()}$
"; } echo $str; } }