diff --git a/deliverable.md b/deliverable.md new file mode 100644 index 0000000..f3d82f6 --- /dev/null +++ b/deliverable.md @@ -0,0 +1,65 @@ +1.- What is object-oriented programming in general terms? + Is the most popular programming paradigm , that relies on the concept of classes and objects. + It is used to structure a software program into simple, reusable pieces of code blueprints. + The four basics of OOP are Inheritance, Encapsulation, Polymorphism, and Data abstraction. + +2.- What is a class? + A class is a mould based on an element in the real world, which can be used both to create objects and to create other moulds. + +3.- What is an object? + An object in OOP is a product of a class. Software objects are often used to model real-world objects. + +4.- What is an instance? + An specific object of a collection. + +5.- What is a property? + Classes can have variables, those variables are called properties. + +6.- What is a method? + Are functions that are defined inside a class that describe the behaviors of an object. + +7.- What is the difference between a function and a method? + Functions are define outside classes. + +8.- What is a constructor? + Allows you to initialize an object's properties upon creation of the object. + In constructors, you set the properties of an object when you create it. + A given house is an instance. + +9.- What is the difference between a class, an object and an instance? + A blueprint for a house design is like a class description. + All the houses built from that blueprint are objects of that class. + +10.- What do we understand about the concept of encapsulation? + Enclosing the internal details of the object to protect from external sources + +11.-What do we understand about the concept of abstraction? + Is a concept in which a class has methods without implementation. The idea is to have a template and let the child class that inherits the parent class implement the method. + +12.-What do we understand about the concept of inheritance? + When a class is a child of another class. The child class will inherit all the public and protected properties and methods from the parent class. + +13.- What do we understand about the concept of polymorphism? + Is the ability of an object to overwrite methods, whit the same name but doing different things. + +14.- What do we understand about the concept of Overload? + Is the ability of a class to have several methods with the same name and to execute one or the other depending on the parameters passed in the call. + +15.-What do we understand about the concept of Override? + Is the ability of a class to modify one inherit method. + +16.- What differences exist between the concept of Overload and Override? + Overload methods are in the same class. + +17.- What is a static class? + They have methods and variables that can be used without the need to instantiate the class. + +18.- Look for 3 advantages over object-oriented programming compared to other programming paradigms + Reuse of code through inheritance. Dont repeat yourself. + Effective problem solving, it is better to face many small problems than one big, fat one. + Security. + +19.- Look for disadvantages of this paradigm. + Learning curve seems steeper than procedural. + More time, more size, more effort + Lower performance, compared to procedural programs, OOP systems are much slow. \ No newline at end of file diff --git a/README.md b/docs/README.md similarity index 100% rename from README.md rename to docs/README.md 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/exercise.php b/exercise.php new file mode 100644 index 0000000..5c6a737 --- /dev/null +++ b/exercise.php @@ -0,0 +1,158 @@ +$ingredients = $ingredients; + $this->$kcal = $kcal; + $this->$cookingTime = $cookingTime; + } + + function __destruct() + { + echo "Recipe out"; + } + + //? METHODS + + public function isVegan($ingredients) + { + + return array_intersect(self::NOTVEGANINGREDIENTS, $ingredients) !== [] ? false : true; + } + + public function lowKcal($kcal) + { + return $kcal <= 100 ? true : false; + } + + //? GETTERS & SETTERS + /** + * Get the value of ingredients + */ + public function getIngredients() + { + return $this->ingredients; + } + + /** + * Set the value of ingredients + * + * @return self + */ + public function setIngredients($ingredients) + { + $this->ingredients = $ingredients; + + return $this; + } + + /** + * Get the value of kcal + */ + public function getKcal() + { + return $this->kcal; + } + + /** + * Set the value of kcal + * + * @return self + */ + public function setKcal($kcal) + { + $this->kcal = $kcal; + + return $this; + } + + /** + * Get the value of cookingTime + */ + public function getCookingTime() + { + return $this->cookingTime; + } + + /** + * Set the value of cookingTime + * + * @return self + */ + public function setCookingTime($cookingTime) + { + $this->cookingTime = $cookingTime; + + return $this; + } +} + +abstract class RiceRecipe extends Recipe +{ + public $ingredients = ["rice"]; + + private $extraIngredients; + + public function __construct($ingredients, $kcal, $cookingTime, $extraIngredients) + { + parent::__construct($ingredients, $kcal, $cookingTime); + $this->$extraIngredients = $$extraIngredients; + } + + public function lowKcal($kcal) + { + return $kcal <= 180 ? true : false; + } + + public function insertExtraIngredients() + { + foreach (self::$extraIngredients as $ingredient) { + array_push($ingredients, $ingredient); + } + } + + /** + * Get the value of extraIngredients + */ + public function getExtraIngredients() + { + return $this->extraIngredients; + } + + /** + * Set the value of extraIngredients + * + * @return self + */ + public function setExtraIngredients($extraIngredients) + { + $this->extraIngredients = $extraIngredients; + + return $this; + } +} + +class RiceMangoRecipe extends RiceRecipe +{ + public $ingredients = ["rice", "mango"]; + + public function cousinLuca() + { + echo "FULL DE MANGO"; + } +} + +interface HealthyFood +{ + public function isVegan($ingredients); + public function lowKcal($kcal); +}