fork download
  1. <?php
  2.  
  3. //PRODUCT
  4. abstract class Product
  5. {
  6. abstract function getName();
  7. }
  8.  
  9. class ProductOne extends Product
  10. {
  11. public function getName(){
  12. echo "Product One";
  13. }
  14. }
  15.  
  16. class ProductTwo
  17. {
  18. public function getName(){
  19. echo "Product Two";
  20. }
  21. }
  22.  
  23. //CREATOR
  24. abstract class ProductCreator
  25. {
  26. abstract function getProduct();
  27. }
  28.  
  29. class ProductOneCreator extends ProductCreator
  30. {
  31. public function getProduct(){
  32. return new ProductOne();
  33. }
  34. }
  35.  
  36. class ProductTwoCreator extends ProductCreator
  37. {
  38. public function getProduct(){
  39. return new ProductTwo();
  40. }
  41. }
  42.  
  43. $creator_one = new ProductOneCreator();
  44. $product_one = $creator_one->getProduct();
  45.  
  46. $product_one = new ProductOne();
Success #stdin #stdout 0.02s 52480KB
stdin
Standard input is empty
stdout
Standard output is empty