DEV Community

Cover image for -Object oriented programming -Callback hell -Async/Sync js -Promise
Husniddin6939
Husniddin6939

Posted on

-Object oriented programming -Callback hell -Async/Sync js -Promise

Object oriented programming contains 4 pillars

Image description

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();
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

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.

  1. 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
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →