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
65 changes: 65 additions & 0 deletions deliverable.md
Original file line number Diff line number Diff line change
@@ -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.
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.
File renamed without changes.
158 changes: 158 additions & 0 deletions exercise.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php
class Recipe implements HealthyFood
{

private $ingredients = [];
private $kcal = [];
private $cookingTime = [];
const NOTVEGANINGREDIENTS = ["meat", "chicken", "egg", "fish", "milk"];

//? CONSTRUCTOR AND DESTRUCTOR

public function __construct($ingredients, $kcal, $cookingTime)
{
$this->$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);
}