diff --git a/abstract-class.php b/abstract-class.php new file mode 100644 index 0000000..97518ee --- /dev/null +++ b/abstract-class.php @@ -0,0 +1,44 @@ +name = $name; + $this->whiskerType = $whiskerType; + } + abstract public function whoAreYou() : string; +} + +// Child classes +class Leon extends Feline { + public function whoAreYou() : string { + return "I'm a king! I'm a $this->name!"; + } +} + +class Pantera extends Feline { + public function whoAreYou() : string { + return "I'm a very fast ! I'm a $this->name!"; + } +} + +class Tiger extends Feline { + public function whoAreYou() : string { + return "I'm a cute! I'm a $this->name!"; + } +} + +// Create objects from the child classes +/*$leon = new Leon("Leon", "long"); +echo $leon->whoAreYou(); +echo "
"; + +$pantera = new Pantera("Pantera", "median"); +echo $pantera->whoAreYou(); +echo "
"; + +$tiger = new Tiger("Tiger", "very long"); +echo $tiger->whoAreYou();*/ +?> diff --git a/animal-class.php b/animal-class.php new file mode 100644 index 0000000..524bcfa --- /dev/null +++ b/animal-class.php @@ -0,0 +1,66 @@ +name=$name; + $this->type=$type; + $this->age=$age; + $this->vertebrates=$vertebrates; + $this->warmBlooded=$warmBlooded; +} + + +public function showAnimal(string $name, string $type, $age, bool $vertebrates, bool $warmBlooded){ + $subType = true; + $blood = true; + if ($vertebrates === true){ + $subType = "vertebrates"; + }else{ + $subType = "invertebrates"; + } + + if( $warmBlooded === true){ + $blood = "warm-blooded"; + }else{ + $blood = "cold-blooded"; + } + +echo " +

$name

+ Type: $type,
+ Subtype: $subType,
+ Age: $this->age,
+ Group: $blood,
"; + +} + +public function canBreath(string $name, string $breath){ + echo "

How Do $name Breathe?

$breath"; +} + +public function canMove(string $name, string $movement){ + echo "

How Do $name move?

$movement"; +} + +public function makeSound(string $name, string $sound){ + echo "

Does $name make any sound?

$sound"; +} + + + + +public function __destruct(){ + print "Destruct " . __CLASS__ . "\n"; +} +} + +?> + + diff --git a/animal-object.php b/animal-object.php new file mode 100644 index 0000000..7978855 --- /dev/null +++ b/animal-object.php @@ -0,0 +1,78 @@ + + + + + + + + + + Document + + + +
+ +showAnimal("Tiger", "Mammal", 10, true, true); +$tiger->canBreath("Tiger", "The respiratory system consists of the lungs. Just like humans and all mammals, Siberian tigers breathe through their nose and mouth into their lungs."); +$tiger->canMove("Tiger", "They can run, jump, climb. The hind legs of the tiger are longer than their front legs. This characteristic enables them to leap forward distances up to 10 meters."); +$tiger->makeSound("Tiger", "They growl, roar, chuff and moan."); + +$crocodile = new animals("Crocodile", "Reptiles", 25, true, false); +$crocodile->showAnimal("Crocodile", "Reptiles", 25, true, false); +$crocodile->canBreath("Crocodile", "When basking on land with the mouth open, crocodilians breathe mostly through their mouth (the throat/palatal valve is open). When in water, the mouth is usually closed and they breathe mostly through their nostrils."); +$crocodile->canMove("Crocodile", "The right front and left rear legs are lifted and moved forward while the front right and rear left legs, already on the ground, push backwards, propelling the crocodile's body forward."); +$crocodile->makeSound("Crocodile", "Adults crocodiles hiss and bellow at each other. Babies chirp when they hatch."); + +$cat = new cats ("Cat", "Mammal", 2, true, true, "Maine Coon"); +$cat->setAge($cat->getAge()*7); +$age = $cat->age; +$cat->showAnimal("Cat", "Mammal", $age, true, true, "Maine Coon"); +$cat->showBreed("Maine Coon"); +$cat->canBreath("Cat", "A healthy respiratory (breathing) rate for a cat is usually between 20 and 30 breaths per minute."); +$cat->canMove("Cat", "Cats are digitigrade; that is, they walk on their toes."); +#$cat->makeSound("Cat", "Already in ancient Egypt the quintessential sound of a cat was “meow”, which meant “cat”. This sound can last between a fraction of a second and various seconds and cats produce it by opening their mouth and then gradually closing it again.

"); +$cat->makePurr("Cats purr when they're content"); +/*$cat->getMeow(); +$cat->setMeow("Meoooooow");*/ +$cat->makeSound("cat", "meoww"); + + +echo "

INTERFACE"; +//Interface +$dog = new Dog(); +$mouse = new Mouse(); +$animals = array($dog, $mouse); + +foreach($animals as $animal) { + $animal->eat(); + $animal->move(); + } + + +// Create objects from the child classes +echo "

ABSTRACT CLASS

"; +$leon = new Leon("Leon", "long"); +echo $leon->whoAreYou(); +echo "
"; + +$pantera = new Pantera("Pantera", "median"); +echo $pantera->whoAreYou(); +echo "
"; + +$tiger = new Tiger("Tiger", "very long"); +echo $tiger->whoAreYou() . "

"; + +?> + +
+ + \ No newline at end of file diff --git a/animal-with-interitance.php b/animal-with-interitance.php new file mode 100644 index 0000000..d67cd1c --- /dev/null +++ b/animal-with-interitance.php @@ -0,0 +1,41 @@ +breed=$breed; + } + + public function showBreed(string $breed){ + echo "Breed: $breed
"; +} + +public function makePurr(string $purr){ + echo "

Purr: $purr
+ "; +} + +// override // + +public function getAge(){ + return $this->age; +} + +public function setAge($ageNew){ + $this->age = $ageNew; + return $this; +} + +public function makeSound(string $name, string $sound){ + echo "

How speaks a $name?

$sound"; + return $sound; +} + +} + +?> \ No newline at end of file diff --git a/ejemple.php b/ejemple.php new file mode 100644 index 0000000..6d8e2f6 --- /dev/null +++ b/ejemple.php @@ -0,0 +1,176 @@ +// create php 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 // + +property1 = $p1; + $this->property2 = $p2; + $this->property3 = $p3; + } + + public function method1() { + // code here + } + + public function method2() { + // code here + } + + public function method3() { + // code here + } + + public function __destruct() { + // code here + } +} +?> + +// create php class that inherits the base class. +This class must add: +1 static property +1 method // + +property2 = $p2; + } + + public function newMethod() { + // code here + } + + public function method2() { + // code here (override) + } + } + ?> + +// One abstract class with at least: +2 properties +2 methods +// + +property1 = $p1; + $this->property2 = $p2; + } + + abstract public function method1(); + + abstract public function method2(); + } + +?> + + +// One interface that must be implemented by one class. +This interface must have at least 2 methods. // + + + + +// Other option with interface and inheretence // + +age = $age; + $this->fur = $fur; + $this->vertebrates = $vertebrates; + $this->type = $type; + } + + public function __destruct() { + // code here + } + + public function breath() { + // code here + } + + public function move() { + // code here + } + + public function sound() { + // code here + } +} + +class Cat extends Animal { + protected $breed; + + public function __construct($age, $fur, $vertebrates, $type, $breed) { + parent::__construct($age, $fur, $vertebrates, $type); + $this->breed = $breed; + } + + public function purr() { + // code here + } + + public function sound() { + // code here (override) + } + + public function meow() { + // code here + } +} + +abstract class Feline extends Cat { + protected $whisker_type; + + public function throwObjectInstance() { + // code here + } +} + +?> \ No newline at end of file diff --git a/01-classes.php b/ejemplos/01-classes.php similarity index 100% rename from 01-classes.php rename to ejemplos/01-classes.php diff --git a/02-properties.php b/ejemplos/02-properties.php similarity index 100% rename from 02-properties.php rename to ejemplos/02-properties.php diff --git a/03-methods.php b/ejemplos/03-methods.php similarity index 100% rename from 03-methods.php rename to ejemplos/03-methods.php diff --git a/04-getters.php b/ejemplos/04-getters.php similarity index 100% rename from 04-getters.php rename to ejemplos/04-getters.php diff --git a/05-setters.php b/ejemplos/05-setters.php similarity index 100% rename from 05-setters.php rename to ejemplos/05-setters.php diff --git a/06-constructors.php b/ejemplos/06-constructors.php similarity index 100% rename from 06-constructors.php rename to ejemplos/06-constructors.php diff --git a/07-inheritance-problem.php b/ejemplos/07-inheritance-problem.php similarity index 100% rename from 07-inheritance-problem.php rename to ejemplos/07-inheritance-problem.php diff --git a/08-inheritance-solution.php b/ejemplos/08-inheritance-solution.php similarity index 100% rename from 08-inheritance-solution.php rename to ejemplos/08-inheritance-solution.php diff --git a/09-public-private-protected.php b/ejemplos/09-public-private-protected.php similarity index 100% rename from 09-public-private-protected.php rename to ejemplos/09-public-private-protected.php diff --git a/10-static.php b/ejemplos/10-static.php similarity index 100% rename from 10-static.php rename to ejemplos/10-static.php diff --git a/11-const.php b/ejemplos/11-const.php similarity index 100% rename from 11-const.php rename to ejemplos/11-const.php diff --git a/12-abstract-classes.php b/ejemplos/12-abstract-classes.php similarity index 100% rename from 12-abstract-classes.php rename to ejemplos/12-abstract-classes.php diff --git a/13-interfaces.php b/ejemplos/13-interfaces.php similarity index 100% rename from 13-interfaces.php rename to ejemplos/13-interfaces.php diff --git a/14-overriding.php b/ejemplos/14-overriding.php similarity index 100% rename from 14-overriding.php rename to ejemplos/14-overriding.php diff --git a/15-overloading.php b/ejemplos/15-overloading.php similarity index 100% rename from 15-overloading.php rename to ejemplos/15-overloading.php diff --git a/16-namespaces.php b/ejemplos/16-namespaces.php similarity index 100% rename from 16-namespaces.php rename to ejemplos/16-namespaces.php diff --git a/mobileLibs.php b/ejemplos/mobileLibs.php similarity index 100% rename from mobileLibs.php rename to ejemplos/mobileLibs.php diff --git a/interface.php b/interface.php new file mode 100644 index 0000000..68f2016 --- /dev/null +++ b/interface.php @@ -0,0 +1,31 @@ +Dog likes meat
"; + } + + public function move() { + echo "Dog can run, jump, climb
"; + } + } + + + class Mouse implements AliveAnimal { + + public function move() { + echo "Mouse can run, jump, climb
"; + } + + public function eat() { + echo "Mouse likes cheese
"; + } + + } + +?> \ No newline at end of file diff --git a/sound/cat.mp3 b/sound/cat.mp3 new file mode 100644 index 0000000..72d4a37 Binary files /dev/null and b/sound/cat.mp3 differ diff --git a/style.css b/style.css new file mode 100644 index 0000000..bd259d2 --- /dev/null +++ b/style.css @@ -0,0 +1,14 @@ +html{ +width: 60%; +margin-left: 10px; +} + + +h1{ +color: rgb(56, 16, 137); +} + +p{ +color: mediumpurple; +font-weight: bold; +} \ No newline at end of file