├── assets
└── img
│ ├── xampp-app.png
│ ├── xampp-download.png
│ └── xampp-homepage.png
├── 01-classes.php
├── 03-methods.php
├── 05-setters.php
├── mobileLibs.php
├── 06-constructors.php
├── 11-const.php
├── oop-pill
├── practical-pill.php
└── respuestas-teoricas.html
├── 14-overriding.php
├── 02-properties.php
├── 04-getters.php
├── 10-static.php
├── 15-overloading.php
├── 12-abstract-classes.php
├── 08-inheritance-solution.php
├── 07-inheritance-problem.php
├── 13-interfaces.php
├── 09-public-private-protected.php
├── 16-namespaces.php
└── README.md
/assets/img/xampp-app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/juliomc23/oop-basics/HEAD/assets/img/xampp-app.png
--------------------------------------------------------------------------------
/assets/img/xampp-download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/juliomc23/oop-basics/HEAD/assets/img/xampp-download.png
--------------------------------------------------------------------------------
/assets/img/xampp-homepage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/juliomc23/oop-basics/HEAD/assets/img/xampp-homepage.png
--------------------------------------------------------------------------------
/01-classes.php:
--------------------------------------------------------------------------------
1 | ";
21 | var_dump($oldMobile);
22 |
--------------------------------------------------------------------------------
/03-methods.php:
--------------------------------------------------------------------------------
1 | name . " includes a " . $this->chipset . " chipset and " . $this->internalMemory . "GB of internal memory";
19 | }
20 | }
21 |
22 |
23 | $modernMobile = new Mobile();
24 | $modernMobile->name = "Samsung s20";
25 | $modernMobile->chipset = "Exynos";
26 | $modernMobile->internalMemory = 128;
27 |
28 | echo $modernMobile->showSpecs();
29 |
--------------------------------------------------------------------------------
/05-setters.php:
--------------------------------------------------------------------------------
1 | internalMemory;
18 | }
19 |
20 | // setters are methods for changing properties
21 | public function setInternalMemory($internalMemory)
22 | {
23 | echo "* CHANGED internal memory from " . $this->internalMemory;
24 | $this->internalMemory = $internalMemory;
25 | echo " to " . $this->internalMemory;
26 | }
27 | }
28 |
29 | echo "
";
30 |
31 | $modernMobile = new Mobile();
32 | $modernMobile->name = "Samsung s20";
33 | $modernMobile->chipset = "Exynos";
34 | $modernMobile->internalMemory = 128;
35 |
36 |
37 | echo "
";
38 | echo $modernMobile->getInternalMemory();
39 | echo "
";
40 | $modernMobile->setInternalMemory(256);
41 | echo "
";
42 | echo $modernMobile->getInternalMemory();
43 |
--------------------------------------------------------------------------------
/mobileLibs.php:
--------------------------------------------------------------------------------
1 | name = $name;
19 | $this->chipset = $chipset;
20 | $this->internalMemory = $internalMemory;
21 | echo "+ " . $this->name . " CREATED +
";
22 | }
23 |
24 | // PHP will call __destruct at the end of the script, when the object is destructed or the script is stopped or exited.
25 | function __destruct()
26 | {
27 | echo "- DESTROYED : " . $this->name . " includes a " . $this->chipset . " chipset and " . $this->internalMemory . "GB of internal memory -
";
28 | }
29 | }
30 |
31 | // Now we can instantiate a mobile object passing arguments in the correct order
32 | $modernMobile = new Mobile('Samsung s20', 'Exynos', 128);
33 | $oldMobile = new Mobile('BlackBerry', 'ARM', 1);
34 | echo "
";
35 |
--------------------------------------------------------------------------------
/11-const.php:
--------------------------------------------------------------------------------
1 | name = $name;
32 | $this->chipset = $chipset;
33 | $this->internalMemory = $internalMemory;
34 | $this->imei = $imei;
35 | echo "+ CREATED " . $this->name . " WITH " . $this->internalMemory . " INTERNAL MEMORY +
";
36 | }
37 |
38 | // We can access constants with just name
39 | public function runMobileApp()
40 | {
41 | return $this->name . " RUNS " . APPNAME . " : " . Internet::connectInternet();
42 | }
43 | }
44 |
45 | $samsung = new Mobile('Samsung s20', 'Exynos', 128, '000111222333');
46 | echo $samsung->runMobileApp();
47 |
--------------------------------------------------------------------------------
/oop-pill/practical-pill.php:
--------------------------------------------------------------------------------
1 | motor = $motor;
19 | }
20 |
21 | public function setVolante($volante){
22 | return $this->volante = $volante;
23 | }
24 |
25 | public function setRuedas($ruedas){
26 | return $this->ruedas = $ruedas;
27 | }
28 |
29 | public function acelerar()
30 | {
31 | return $this->velocimetro++;
32 | }
33 |
34 | public function frenar()
35 | {
36 | return $this->velocimetro--;
37 | }
38 | }
39 |
40 | $coche = new Vehicle;
41 | $coche->setMotor(124);
42 | var_dump($coche);
43 |
44 |
45 | class Camion extends Vehicle{
46 |
47 | static $remolque;
48 |
49 | public function getRemolque(){
50 | echo "Enganchando el remolque";
51 | }
52 | }
53 |
54 | $trailer = new Camion;
55 | $trailer->getRemolque();
56 | var_dump($trailer);
57 |
58 | abstract class Tanque extends Vehicle{
59 |
60 | private $cañon;
61 | private $cabeza;
62 |
63 | private function disparar(){
64 | echo "Disparandooo";
65 | }
66 |
67 | private function girarCabeza(){
68 | echo "girando cabezal";
69 | }
70 | }
71 |
72 | interface iVehicle{
73 |
74 | public function acelerar();
75 | public function frenar();
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/14-overriding.php:
--------------------------------------------------------------------------------
1 | name = $name;
22 | $this->internalMemory = $internalMemory;
23 | }
24 |
25 | public function getName()
26 | {
27 | return $this->name;
28 | }
29 |
30 | public function getInternalMemory()
31 | {
32 | return $this->internalMemory;
33 | }
34 | }
35 |
36 | // When you extend a class, the subclass inherits all of the public and protected methods from the parent class.
37 | class iPhonePlus extends iPhone
38 | {
39 | //Here we are overriding this method adding extra features that the previous "getName" doesn't have.
40 | public function getName()
41 | {
42 | return "¡The name of this iPhone is $this->name!";
43 | }
44 | }
45 |
46 | $iPhone = new iPhone("iPhone X", "64");
47 | echo $iPhone->getName() . "\n";
48 |
49 | $iPhonePlus = new iPhonePlus("iPhone X Plus", "128");
50 | echo $iPhonePlus->getName();
51 |
--------------------------------------------------------------------------------
/02-properties.php:
--------------------------------------------------------------------------------
1 | ) for accessing properties
18 |
19 | // we can assign those public properties in our class with this syntax
20 | $modernMobile->name = "Samsung s20";
21 | $modernMobile->chipset = "Exynos";
22 | $modernMobile->internalMemory = 128;
23 |
24 | echo "
";
25 |
26 | // we can also access properties value by the arrow operator
27 | echo $modernMobile->chipset;
28 |
29 | // what happens if we assign a non existing value or a wrong value?
30 | $modernMobile->ramMemory = 1;
31 | $modernMobile->internMemory = 8;
32 |
33 | echo "
"; 34 | var_dump($modernMobile); 35 | echo ""; 36 | 37 | echo "
es un modelo de programación en el cual se busca una programación escalable y organizada
15 |una clase es el molde apartir del cual crearemos los nuevos objetos
20 |un objeto es un elemento creado a partir de una clase
25 |una instancia es la creación de ese objeto
30 |una propiedad no es más que un atributo que puede tener ese objeto
35 |un metodo es una acción que puede realizar un objeto
40 |la unica diferencia que hay es que se llama funcion si no pertenece a un objeto, en el momento en el que la funcion esté declarada en el objeto este pasa 45 | a llamarse metodo 46 |
47 |un constructor es otro metodo
52 |57 | clase: es la plantilla de la que se crearán los objetos 58 | objeto: elemento creado de esa plantilla 59 | instancia: momento en el que se crea el nuevo objeto 60 |
61 |la manera en la que declaramos los atributos y metodos de una clase, pueden ser public, private o protected. Dependiendo de como lo hagamos se 66 | comportarán de una manera o de otra 67 |
68 |cuando creamos una clase tenemos que saber que atributos y metodos va a tener esa clase, no podemos ser ni muy abstractos ni muy realistas.
73 |cuando creamos otra clase esta puede heredar los atributos y metodos de la clase principal creada 78 |
79 |tener diferente funcionalidad en una clase, pero compartiendo una misma plantilla
84 |es tener 2 o mas metodos con el mismo nombre pero con distintos parametros
89 |una subclase puede redefinir los metodos heredados cuando necesite cambiar el comportamiento de este metodo
94 |una clase estatica es aquella que no te permite la instanciacion de esta
104 |109 | 1. Reeutilizacion de codigo 110 | 2. Encapsulacion, hacemos mas segura nuestra aplicacion 111 | 3. Mas facilidad para leer y entender nuestro codigo 112 |
113 |118 | es mas dificil de aprender 119 |
120 |
53 |
54 | You have to go to the [download page](https://www.apachefriends.org/es/download.html) and it will automatically recommend installing the latest version available.
55 |
56 |
57 |
58 | Once downloaded and installed, in the case that the Windows operating system you will see the following screen, in which you will only have to start the Apache service.
59 |
60 |
61 |
62 | ## OOP Introduction
63 |
64 | Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).
65 |
66 | ## Project files
67 |
68 | ### [01 - Classes](./01-classes.php)
69 |
70 | The OOP paradigm encapsulates concepts of the real world in what is called as Classes which create Objects. In this file you will learn how to create a class and instanciate it.
71 |
72 | ### [02 - Properties](02-properties.php)
73 |
74 | Class member variables are called properties. In this file, you will learn how to add properties to a class and get them when the class is instantiated.
75 |
76 | ### [03 - Methods](03-methods.php)
77 |
78 | Properties define the characteristics of an object and the methods (functions in a class are called methods) which define the behavior of the Class. In this file you will learn how to create methods inside a class.
79 |
80 | ### [04 - Getters](04-getters.php)
81 |
82 | The get method returns the attribute value, usually there is a get method for each attribute of the class. In this file you will learn how to create **getter** methods.
83 |
84 | ### [05 - Setters](05-setters.php)
85 |
86 | The set method sets the attribute value, usually there is a get method for each attribute of the class. In this file you will learn how to create **setter** methods.
87 |
88 | ### [06 - Constructors](06-constructors.php)
89 |
90 | A constructor allows you to initialize an object's properties upon creation of the object. In this file you will learn how to create the constructor method.
91 |
92 | ### [07 - Inheritance problem](07-inheritance-problem.php)
93 |
94 | There are several disadvantages of not applying inheritance in our code. In this file you will lean what's the problem if you don't apply any inheritance in your code.
95 |
96 | ### [08 - Inheritance soluction](08-inheritance-solution.php)
97 |
98 | The child class will inherit all the public and protected properties and methods from the parent class. In addition, it can have its own properties and methods. In this file you will learn how to apply the inheritance in your code.
99 |
100 | ### [09 - Public, private & protected](09-public-private-protected.php)
101 |
102 | Properties and methods can have access modifiers which control where they can be accessed. In this file you will learn le three access modifiers.
103 |
104 | ### [10 - Static](10-static.php)
105 |
106 | Static properties and methods can be called directly - without creating an instance of the class first. In this file you will learn how to use static properties and methods.
107 |
108 | ### [11 - Const](11-const.php)
109 |
110 | Constants cannot be changed once it is declared. Class constants can be useful if you need to define some constant data within a class. In this file you will learn how to create constants within a class.
111 |
112 | ### [12 - Abstract classes](12-abstract-classes.php)
113 |
114 | Abstract classes and methods are when the parent class has a named method, but need its child class(es) to fill out the tasks. In this file you will learn how to create and use abstract classes.
115 |
116 | ### [13 - Interfaces](13-interfaces.php)
117 |
118 | Interfaces allow you to specify what methods a class should implement.
119 | Interfaces make it easy to use a variety of different classes in the same way. When one or more classes use the same interface, it is referred to as "polymorphism". In this file you will learn how to create and extend interfaces.
120 |
121 | ### [14 - Overriding](14-overriding.php)
122 |
123 | In function overriding, both parent and child classes should have same function name with and number of arguments. In this file you will learn how to implement overriding.
124 |
125 | ### [15 - Overloading](15-overloading.php)
126 |
127 | Function overloading contains same function name and that function preforms different task according to number of arguments. In this file you will learn how to implement overloading.
128 |
129 | ### [16 - Namespaces](16-namespaces.php)
130 |
131 | Namespaces are qualifiers that solve two different problems:
132 |
133 | 1. They allow for better organization by grouping classes that work together to perform a task
134 | 2. They allow the same name to be used for more than one class
135 |
136 | In this file you will learn how to create and use namespaces.
137 |
--------------------------------------------------------------------------------