Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

interface Art{
public function printCategory():string;
public function printCompany():string;
}

?>
46 changes: 46 additions & 0 deletions Plays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

require_once("./StageSpectacles.php");

class Plays extends stageSpectacles{
protected $datePremiere;
protected $author;
static $theater = "Apollo Theater";

public function __construct(string $spectacleName, string $spectacleType, string $category, int $performersNumber, string $company, string $author)
{
parent::__construct($spectacleName, $spectacleType, $category, $performersNumber, $company);
$this->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 "<br>It is a play.<br><br>";
}

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

public function __destruct(){

}
}

?>
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

20 changes: 20 additions & 0 deletions Spectacles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

require_once('./Interface.php');

abstract class Spectacles implements Art{
const SPECTACLE = 'spectacle';
public $spectacleName;
protected $spectacleType;

public function __construct(string $spectacleName, string $spectacleType)
{
$this->spectacleName = $spectacleName;
$this->spectacleType = $spectacleType;
}

abstract function printCategory():string;
abstract function printCompany():string;
}

?>
52 changes: 52 additions & 0 deletions StageSpectacles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

require_once('./Spectacles.php');

class StageSpectacles extends spectacles{
protected $category;
protected $performersNumber;
protected $company;

public function __construct(string $spectacleName, string $spectacleType, string $category, int $performersNumber, string $company)
{
parent::__construct($spectacleName, $spectacleType);
$this->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 . ".<br>";
}

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?
"<br><br>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.":
"<br><br>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 "<br><br>The company's name is: ".$this->company.".";
}

public function __destruct(){
echo "<br><br>The " . self::SPECTACLE . "/s has/have been successfully registered" . ".<br><br>";
}
}

?>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 46 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

require_once('./Spectacles.php');
require_once('./StageSpectacles.php');
require_once('./Plays.php');

echo Plays::$theater." 2023 programme.<br>Plase introduce the registration information.<br><br>";
echo "<br>";
echo "<hr>";
$spectacle = New StageSpectacles("Macbeth", "stage", "drama", 9, "ububu");
echo "<br>";
echo $spectacle->welcome();
echo "<br><br>";
$macbeth = New Plays("Macbeth", "stage", "drama", 9, "ububu", "Shakespeare");
$macbeth->setDate("3-2-2024");
echo $macbeth->spectacleNameAndType();
echo "<br>";
echo $macbeth->welcome();
echo "<br>";
echo $macbeth->getType();
echo $macbeth->printCategory();
echo $macbeth->printCompany();
echo $macbeth->ensembleSize();
echo "<br><br>";
echo $macbeth->updatePerformers(8);
echo "<br><br>";
echo $macbeth->updatePerformers(12);
echo "<br><br>";
echo $macbeth->getDate();

echo "<br><br>";
echo "<hr>";
$ubuRoi = New Plays("Ubu Roi", "visual", "absurd", 15, "La Infantona", "Alfred Jarry");
$ubuRoi->setDate("12-6-2023");
echo "<br>";
echo $ubuRoi->spectacleNameAndType();
echo "<br>";
echo $ubuRoi->welcome();
echo "<br>";
echo $ubuRoi->getType();
echo $ubuRoi->printCategory();
echo $ubuRoi->printCompany();
echo $ubuRoi->ensembleSize();
echo "<br><br>";
echo $ubuRoi->getDate();
?>
17 changes: 17 additions & 0 deletions template.txt
Original file line number Diff line number Diff line change
@@ -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