The property's and functions of the functionality/component are all put together inside a object.
As opposed to encapsulation, abstraction tends to generalize things, hiding unwanted data and revealing necessary data.
Polymorphism, in short, is the ability for data to be represented in more than one way.
Elements inherit the properties and methods of the father class.
- Public: access this property everywhere. Public methods can access private properties
- Private: only accessibly inside the class.
- Protected: access inside the original and the children of that class.
Function that runs when a new instance of the class is declared.
public function __construct() {
echo 'Object declared';
}
Function that runs when the call to an object finishes.
public function __destructor() {
echo 'Object last run';
}
A new class inherits the properties of the extended class.
class Human extends Animal {
// all the animal public and protected
// properties and methods are inherit
}
"Get the parent of this object then call its constructor".
class Son extends Father
{
function __construct($name, $email)
{
parent::__construct($name);
$this->email = $email;
}
}
Class that can only be inherit. The abstract methods can have a body. Only declare the name, properties & result.
abstract class Think
{
public abstract function remember ($try) : string;
}
Properties and methods of a class can be static with the purpose of call them without the need of declare the class.
class User {
private static $password = 1234;
public statis function getPassword () {
return self::$password;
}
}
echo User::$password; // returns 1234;
Used to declare what kind of values a variable must contain.
public string $animal = 'Dog';
Programming paradigm that uses abstraction to encapsulate all the
concepts and functionalities of a abstract element. Its used to have a
better organization of the code, better escalability and repeat less code.
Blueprint that contains all the properties and functionalities of a main
concept. So from that class we can create various elements with the same
caracteristics. The classes can inherit other classes public and protected
properties and methods.
A list of properties and functions.
The declaration of a object.
Variable inside a object that contains data value.
Function inside a object.
A method its a called always from the object that contains it.
Magic method from a class that runs automatically when a object is created.
It is normally used to add properties on the object declaration.
Class is the template of a future object/s. An instance indicates the
relation between object and class. So a object its a instance of a class.
Using the __call magic method to change the function body and behavior
depending on the number and type of arguments given.
class Thing {
function __call ($nameFunction, $arguments) {
switch(count($arguments)) {
case 1:
return 'Only one argument';
case 2:
return 'Two arguments';
}
}
}
$thing = new Thing;
echo $thing->argumentCounter('a'); // Only one argument
echo $thing->argumentCounter('a','b'); // Two arguments
Replace a parent method in a child class.
Overload its a magic method to create diferent outputs for the same method.
Override only refears to changing the logic of a method inherit form the
parent class.
1. DRY code.
2. Better scalability.
3. Organized code.
1. More complex.
2. Needs planing.