Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface StoreInterface
- {
- public function __construct(string $name,int $price);
- public function getPrice():int;
- public function showProducts():string ;
- }
- class Store implements StoreInterface
- {
- private $price;
- private $name;
- public function getPrice(): int
- {
- return $this->price;
- }
- public function showProducts(): string
- {
- return $this->name." | " . $this->price;
- }
- public function __construct(string $name, int $price)
- {
- $this->name = $name;
- $this->price = $price;
- }
- }
- class StoreManager
- {
- private $products;
- public function __construct(array $products)
- {
- $this->products=$products;
- }
- public function getName(): array
- {
- $name = [];
- foreach ($this->products as $product)
- {
- $name[] = $product->showProducts();
- }
- return $name;
- }
- }
- $products = [
- $apple = new Store("apple",20),
- $banana = new Store("banana",40)
- ];
- $storeManager = new StoreManager($products);
- echo implode("|", $storeManager->getName());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement