factory - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of factory.php

  1. <?php
  2.  
  3. abstract class Factory{
  4.     
  5.     abstract public function factoryMethod() : FactoryInterface;
  6.     
  7.     public function run(){
  8.         $method = $this->factoryMethod();
  9.         $method->test();
  10.     }
  11.     
  12. }
  13.  
  14. interface FactoryInterface {
  15.     public function test();
  16. }
  17.  
  18. class LetsGo implements FactoryInterface{
  19.     public function test(){
  20.         echo 'Working';
  21.     }
  22.     
  23. }
  24.  
  25. function client(FactoryInterface $interface){
  26.     $interface-> test();
  27. };
  28.  
  29. client(new LetsGo());
File Description
  • factory
  • PHP Code
  • 23 Mar-2021
  • 478 Bytes
You can Share it: