Object oriented programming contains 4 pillars
Object oriented programming - We group related variables and function that operate on them into objects and it is what we call encapsulation.
Let's show an example of this in action.
function getSalery(baseSalery, overtime, rate){
return baseSalery + (overtime*rate);
}
let employee = {
baseSalery:24000,
overtime:20,
rate:10,
getSalery: function(){
return this.baseSalery + (this.overtime*rate);
}
};
employee.getSalery();
When type code in Object oriented way, our functions end up having fewer parametrs so...
The best functions are those with no parametrs
it is easier to use and mountain it in fewer parametr functions.
##ABSTRUCTION
Imagine abstriction think of a mobile phone on our hand as an object, this devise has a lots of tiny elements on the inside and we only and simply use it by tuchching and we don't care what happened inside, all complexity hidden from us - This is abstraction in practise.
We can use the same technique in objects, we can hide same of the proporties and methods from the outside and throught this way we echiave a couple of benifits.
- Using an undarstanding an object with a few properties and methods is easier than an object with several properties and methods.
2.Secondly, it helps us reduce the impact of change. Let's imagine if we change inner or private methods, none of these changes will leak to the outside coz we don't have any code that touches these method outside of their content object, we may delete a method or change its parametrs but none of these changes will impact the rest of the aplications code.
So with abstraction we reduce the impact of change.
## Inheritance
Top comments (0)