Advertisement
Guest User

Factory

a guest
May 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. interface Door
  2. {
  3. public function getWidth(): float;
  4. public function getHeight(): float;
  5. }
  6.  
  7. class WoodenDoor implements Door
  8. {
  9. protected $width;
  10. protected $height;
  11.  
  12. public function __construct(float $width, float $height)
  13. {
  14. $this->width = $width;
  15. $this->height = $height;
  16. }
  17.  
  18. public function getWidth(): float
  19. {
  20. return $this->width;
  21. }
  22.  
  23. public function getHeight(): float
  24. {
  25. return $this->height;
  26. }
  27.  
  28.  
  29. class DoorFactory
  30. {
  31. public static function makeDoor($width, $height): Door
  32. {
  33. return new WoodenDoor($width, $height);
  34. }
  35. }
  36.  
  37. //And then it can be used as
  38.  
  39. $door = DoorFactory::makeDoor(100, 200);
  40. echo 'Width: ' . $door->getWidth();
  41. echo 'Height: ' . $door->getHeight();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement