Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1.  
  2. interface StoreInterface
  3. {
  4. public function __construct(string $name,int $price);
  5. public function getPrice():int;
  6. public function showProducts():string ;
  7.  
  8. }
  9.  
  10. class Store implements StoreInterface
  11. {
  12.  
  13. private $price;
  14. private $name;
  15.  
  16.  
  17. public function getPrice(): int
  18. {
  19. return $this->price;
  20. }
  21.  
  22. public function showProducts(): string
  23. {
  24. return $this->name." | " . $this->price;
  25. }
  26.  
  27. public function __construct(string $name, int $price)
  28. {
  29. $this->name = $name;
  30. $this->price = $price;
  31.  
  32. }
  33. }
  34.  
  35. class StoreManager
  36. {
  37. private $products;
  38. public function __construct(array $products)
  39. {
  40. $this->products=$products;
  41. }
  42.  
  43. public function getName(): array
  44. {
  45. $name = [];
  46.  
  47. foreach ($this->products as $product)
  48. {
  49. $name[] = $product->showProducts();
  50. }
  51.  
  52. return $name;
  53. }
  54.  
  55. }
  56.  
  57. $products = [
  58. $apple = new Store("apple",20),
  59. $banana = new Store("banana",40)
  60. ];
  61. $storeManager = new StoreManager($products);
  62.  
  63.  
  64. echo implode("|", $storeManager->getName());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement