diff --git a/Interface.php b/Interface.php new file mode 100644 index 0000000..cb17257 --- /dev/null +++ b/Interface.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/Plays.php b/Plays.php new file mode 100644 index 0000000..4615edf --- /dev/null +++ b/Plays.php @@ -0,0 +1,46 @@ +author = $author; + } + + public function welcome():string{ + return "Welcome to the Apollo Theater 2023 programme."; + } + + public function setDate($date){ /* :string */ + $this->datePremiere = $date; + } + + public function getDate(){ /* :string */ + return "The premiere date is : ".$this->datePremiere."."; + } + + public function getType(){ + $this->category=="drama"? + $this->isPlay(): $this->isNotPlay(); + } + + public function isPlay(){ + echo "
It is a play.

"; + } + + public function isNotPlay(){ + echo "
It is not a play.

"; + } + + public function __destruct(){ + + } +} + +?> \ No newline at end of file diff --git a/README.md b/README.md index e644e6a..70d9682 100644 --- a/README.md +++ b/README.md @@ -134,3 +134,14 @@ Namespaces are qualifiers that solve two different problems: 2. They allow the same name to be used for more than one class In this file you will learn how to create and use namespaces. + +## OOP Pill + +### Author comments + +In this pill I created three different classes inherited from the next one. The top one being abstract and the base one defining the methods indicated in the abstract taken from the interface. + +The idea behind is a theater system that register different plays for the next season and need certain info. If we instantiate the method welcome from the class StageSpectacles it will return a message indicating us to add more info which means we need to instantiate from the class Plays. If we call the same method in this class we will be able to enter the system. This is called method overloading. + +Also a property overriding is shown when the number of artists is below the indicated one. A message will be shown to update it and when the number meets the requirement it will allow us to continue. + diff --git a/Spectacles.php b/Spectacles.php new file mode 100644 index 0000000..445f997 --- /dev/null +++ b/Spectacles.php @@ -0,0 +1,20 @@ +spectacleName = $spectacleName; + $this->spectacleType = $spectacleType; + } + + abstract function printCategory():string; + abstract function printCompany():string; +} + +?> \ No newline at end of file diff --git a/StageSpectacles.php b/StageSpectacles.php new file mode 100644 index 0000000..ac174d5 --- /dev/null +++ b/StageSpectacles.php @@ -0,0 +1,52 @@ +category = $category; + $this->performersNumber = $performersNumber; + $this->company = $company; + } + + public function welcome():string{ + return "To reach the Apollo Theater 2023 programme, please supply more information."; + } + + public function spectacleNameAndType():string{ + return "This " . self::SPECTACLE . " is called " . $this->spectacleName . " and is of type " . $this->spectacleType . ".
"; + } + + public function printCategory():string{ + return $this->category=="drama"? + "This play is of category: ".$this->category.".": + "This perform is of category: ".$this->category."."; + } + + public function ensembleSize():string{ + return $this->performersNumber<10? + "

This play has ".$this->performersNumber." performers and therefore is a small ensemble. Please update the number of performers for the Apollo Theater to accept this play.": + "

This play has ".$this->performersNumber." performers and therefore is a big ensemble."; + } + + public function updatePerformers($newPerformersNumber){ + $this->performersNumber = $newPerformersNumber; + return $this->performersNumber<10? "Please update again. ".$this->performersNumber." performer is not enough." : "This amount of performers is perfect."; + } + + public function printCompany():string{ + return "

The company's name is: ".$this->company."."; + } + + public function __destruct(){ + echo "

The " . self::SPECTACLE . "/s has/have been successfully registered" . ".

"; + } +} + +?> \ No newline at end of file diff --git a/01-classes.php b/examples/01-classes.php similarity index 100% rename from 01-classes.php rename to examples/01-classes.php diff --git a/02-properties.php b/examples/02-properties.php similarity index 100% rename from 02-properties.php rename to examples/02-properties.php diff --git a/03-methods.php b/examples/03-methods.php similarity index 100% rename from 03-methods.php rename to examples/03-methods.php diff --git a/04-getters.php b/examples/04-getters.php similarity index 100% rename from 04-getters.php rename to examples/04-getters.php diff --git a/05-setters.php b/examples/05-setters.php similarity index 100% rename from 05-setters.php rename to examples/05-setters.php diff --git a/06-constructors.php b/examples/06-constructors.php similarity index 100% rename from 06-constructors.php rename to examples/06-constructors.php diff --git a/07-inheritance-problem.php b/examples/07-inheritance-problem.php similarity index 100% rename from 07-inheritance-problem.php rename to examples/07-inheritance-problem.php diff --git a/08-inheritance-solution.php b/examples/08-inheritance-solution.php similarity index 100% rename from 08-inheritance-solution.php rename to examples/08-inheritance-solution.php diff --git a/09-public-private-protected.php b/examples/09-public-private-protected.php similarity index 100% rename from 09-public-private-protected.php rename to examples/09-public-private-protected.php diff --git a/10-static.php b/examples/10-static.php similarity index 100% rename from 10-static.php rename to examples/10-static.php diff --git a/11-const.php b/examples/11-const.php similarity index 100% rename from 11-const.php rename to examples/11-const.php diff --git a/12-abstract-classes.php b/examples/12-abstract-classes.php similarity index 100% rename from 12-abstract-classes.php rename to examples/12-abstract-classes.php diff --git a/13-interfaces.php b/examples/13-interfaces.php similarity index 100% rename from 13-interfaces.php rename to examples/13-interfaces.php diff --git a/14-overriding.php b/examples/14-overriding.php similarity index 100% rename from 14-overriding.php rename to examples/14-overriding.php diff --git a/15-overloading.php b/examples/15-overloading.php similarity index 100% rename from 15-overloading.php rename to examples/15-overloading.php diff --git a/16-namespaces.php b/examples/16-namespaces.php similarity index 100% rename from 16-namespaces.php rename to examples/16-namespaces.php diff --git a/mobileLibs.php b/examples/mobileLibs.php similarity index 100% rename from mobileLibs.php rename to examples/mobileLibs.php diff --git a/index.php b/index.php new file mode 100644 index 0000000..83ceee7 --- /dev/null +++ b/index.php @@ -0,0 +1,46 @@ +Plase introduce the registration information.

"; +echo "
"; +echo "
"; +$spectacle = New StageSpectacles("Macbeth", "stage", "drama", 9, "ububu"); +echo "
"; +echo $spectacle->welcome(); +echo "

"; +$macbeth = New Plays("Macbeth", "stage", "drama", 9, "ububu", "Shakespeare"); +$macbeth->setDate("3-2-2024"); +echo $macbeth->spectacleNameAndType(); +echo "
"; +echo $macbeth->welcome(); +echo "
"; +echo $macbeth->getType(); +echo $macbeth->printCategory(); +echo $macbeth->printCompany(); +echo $macbeth->ensembleSize(); +echo "

"; +echo $macbeth->updatePerformers(8); +echo "

"; +echo $macbeth->updatePerformers(12); +echo "

"; +echo $macbeth->getDate(); + +echo "

"; +echo "
"; +$ubuRoi = New Plays("Ubu Roi", "visual", "absurd", 15, "La Infantona", "Alfred Jarry"); +$ubuRoi->setDate("12-6-2023"); +echo "
"; +echo $ubuRoi->spectacleNameAndType(); +echo "
"; +echo $ubuRoi->welcome(); +echo "
"; +echo $ubuRoi->getType(); +echo $ubuRoi->printCategory(); +echo $ubuRoi->printCompany(); +echo $ubuRoi->ensembleSize(); +echo "

"; +echo $ubuRoi->getDate(); +?> \ No newline at end of file diff --git a/template.txt b/template.txt new file mode 100644 index 0000000..4ccbd59 --- /dev/null +++ b/template.txt @@ -0,0 +1,17 @@ +Base class that will be inherited at least once. +This base case must have at least: +3 properties +3 methods +1 constructor and 1 destructor +One class that inherits the base class. +This class must add: +1 static property +1 method +This class must override: +1 property +1 method +One abstract class with at least: +2 properties +2 methods +One interface that must be implemented by one class. +This interface must have at least 2 method