boss_factorz- - 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 boss_factorz-.php

  1. <?php
  2. abstract class ApptEncoder
  3. {
  4. abstract public function encode(): string;
  5. }
  6. // listing 09.14
  7. class BloggsApptEncoder extends ApptEncoder
  8. {
  9. public function encode(): string
  10. {
  11. return "Appointment data encoded in BloggsCal format\n";
  12. }
  13. }
  14. // listing 09.15
  15. class MegaApptEncoder extends ApptEncoder
  16. {
  17. public function encode(): string
  18. {
  19. return "Appointment data encoded in MegaCal format\n";
  20. }
  21. }
  22.  
  23. class CommsManager
  24. {
  25. const BLOGGS = 1;
  26. const MEGA = 2;
  27. private $mode;
  28. public function __construct(int $mode)
  29. {
  30. $this->mode = $mode;
  31. }
  32. public function getApptEncoder(): ApptEncoder
  33. {
  34. switch ($this->mode) {
  35. case (self::MEGA):
  36. return new MegaApptEncoder();
  37. default:
  38. return new BloggsApptEncoder();
  39. }
  40. }
  41. }
  42. // listing 09.18
  43. $man = new CommsManager(CommsManager::MEGA);
  44. print (get_class($man->getApptEncoder())) . "\n";
  45. $man = new CommsManager(CommsManager::BLOGGS);
  46. print (get_class($man->getApptEncoder())) . "\n";
File Description
  • boss_factorz-
  • PHP Code
  • 20 Mar-2021
  • 904 Bytes
You can Share it: