id; } } abstract class BaseList{ protected $lastId; protected $list; public function __construct(){ $this->lastId=1; $this->list=array(); } public abstract function add($params); public function display(){ for($i=0;$ilist);$i++){ $this->list[$i]->display(); } } public function update($params){ for($i=0;$ilist);$i++){ if($this->list[$i]->getId()==$params['id']){ $this->list[$i]->update($params); break; } } } public function delete($id){ for($i=0;$ilist);$i++){ if($this->list[$i]->getId()==$id){ array_splice($this->list,$i,1); break; } } } } class Category extends BaseEntity{ private $name; public function __construct($params){ $this->id=$params['id']; $this->name=$params['name']; } public function display(){ echo $this->id.". ".$this->name."
"; } public function update($params){ $this->id=$params['id']; $this->name=$params['name']; } public function __destruct(){ $this->id=null; $this->name=null; } } class Property extends BaseEntity{ private $name; private $units; public function __construct($params){ $this->id=$params['id']; $this->name=$params['name']; $this->units=$params['units']; } public function display(){ echo $this->id.". ".$this->name." (".$this->units.")
"; } public function update($params){ $this->id=$params['id']; $this->name=$params['name']; $this->units=$params['units']; } public function __destruct(){ $this->id=null; $this->name=null; $this->units=null; } } class Backpack extends BaseEntity{ private $model; private $vendor; private $price; private $category; private $properties; public function __construct($params){ $this->id=$params['id']; $this->model=$params['model']; $this->vendor=$params['vendor']; $this->price=$params['price']; $this->category=$params['category']; $this->properties=$params['properties']; } public function display(){ echo $this->id.". ".$this->vendor." ".$this->model."
"; echo "Категорія: ".$this->category."
"; echo "Ціна: ".$this->price." грн
"; echo "Характеристики:
"; foreach (json_decode($this->properties) as $propertyName => $propertyValue) { echo $propertyName . ": " . $propertyValue . "
"; } } public function update($params){ $this->id=$params['id']; $this->model=$params['model']; $this->vendor=$params['vendor']; $this->price=$params['price']; $this->category=$params['category']; $this->properties=$params['properties']; } public function __destruct(){ $this->id=null; $this->model=null; $this->vendor=null; $this->price=null; $this->category=null; $this->properties=null; } } class CategoryList extends BaseList{ public function add($params){ $params['id']=$this->lastId; $newObj=new Category($params); array_push($this->list,$newObj); $this->lastId++; } } class PropertyList extends BaseList{ public function add($params){ $params['id']=$this->lastId; $newObj=new Property($params); array_push($this->list,$newObj); $this->lastId++; } } class BackpackList extends BaseList{ public function add($params){ $params['id']=$this->lastId; $newObj=new Backpack($params); array_push($this->list,$newObj); $this->lastId++; } } /*$a=new Property(1, "Вага", "кг"); $a->display(); $a=new Backpack(1,"Flare", "Osprey","2000","Міські рюкзаки", '{"Вага":"0.8 кг", "Об\'єм":"60 л"}'); $a->display();*/ /*$a=new Category(1,"Похідні рюкзаки"); $b=new Category(2,"Міські рюкзаки"); $a->display(); $b->display(); $a->update(1,"Експедиційні рюкзаки"); $a->display();*/ /*$a=new CategoryList(); $a->add(['name'=>'Похідні рюкзаки']); $a->add(['name'=>'Міські рюкзаки']); $a->display(); $a->update([ 'id'=>'1', 'name'=>'Експедиційні рюкзаки' ]); $a->delete(1); $a->display();*/ /*$b=new PropertyList(); $b->add( ['name'=>'Вага', 'units'=>'кг'] ); $b->add( ['name'=>'Об\'єм', 'units'=>'л'] ); $b->display(); $b->update( ['id'=>'1', 'name'=>'Маса', 'units'=>'г'] ); $b->display(); $b->delete(1); $b->display();*/ $c=new BackpackList(); $c->add( [ 'model'=>'Flare', 'vendor'=>'Osprey', 'price'=>'2000', 'category'=>'Міські рюкзаки', 'properties'=>'{"Вага":"0.8 кг", "Об\'єм":"20 л"}' ] ); $c->add( [ 'model'=>'Kestrel', 'vendor'=>'Osprey', 'price'=>'6000', 'category'=>'Похідні рюкзаки', 'properties'=>'{"Вага":"1.8 кг", "Об\'єм":"60 л"}' ] ); $c->display(); $c->update( [ 'id'=>'2', 'model'=>'Kestrel', 'vendor'=>'Osprey', 'price'=>'8000', 'category'=>'Похідні рюкзаки', 'properties'=>'{"Вага":"1.8 кг", "Об\'єм":"60 л"}' ] ); $c->display(); $c->delete(1); $c->display(); ?>