We will start from object oriented programming basics like
So, Object Oriented Programming is made up of 3 words. Object + Oriented + Programming
So, if we have to understand Object Oriented Programming, then we will have to understand Object first.
Object -> 1st Concept
Object – Object means a Real Time Object like Pen, Paper, Bill, Building, Rent Receipt etc…
Every Object is associated with a class, So we have to understand class as well.
Class -> 2nd Concept
Class – class means the layout or the blueprint of an object, like design of the pen, Layout of a Bill, Blueprint of a Building, Format of a Rent Receipt.
Then, we have a constructor associated to every class, so we must understand constructor as well.
Constructor -> 3rd Concept
Constructor – Constructor is a special type of function, which gets executed as soon as the object of a class is created.
Then we have to understand a 4th concept, Types of Object
Types of Objects -> 4th Concept
Methods -> 5th Concept
Methods – Methods are same like a function, but a method is always associated with a class or an object, there can be no method without a class or object. function is never associated with any class.
Differnce between function and method -> 6th Concept
Then There are 4 pillars of Object Oriented Programming
Let’s understand these concepts first.
Inheritance – Let’s take an example of a Car of Suzuki like Celerio. If you search for Celerio online, then you will find that there are different variants available of Celerio like lxi, vxi, zxi and zxi+. The lxi variant is the base model, and all the other variants vxi, zxi and zxi+ are made using the lxi base model, Suzuki didn’t made all the variants from scratch, They have just made a base model and used the base model to make other variants where some extra features are added. So, Inheritance is the way that genetic information is passed from a parent to a child. So, here base model is parent and all the other variants are child.
There are 2 types of Inheritance in Javascript
Prototypes and Prototypal Inheritance -> 7th Concept
Inheritance using extends keyword & Parent Child Concept -> 8th Concept
Polymorphism – Polymorphism meaning is many form, So, anything that is found in many forms, is said to have a property of Polymorphism.
Let’s take an example of Laptops, We see that the laptops in the market come with different configurations like We get
So, Laptops are coming in different forms, This is called Polymorphism. So, we have following concepts in polymorphism
function overloading -> 9th Concept
function overriding -> 10th Concept
method overloading -> 11th Concept
method overriding -> 12th Concept
Constructor Overloading -> 13th Concept
Constructor Overriding -> 14th Concept
Then we have concept of Abstraction and Encapsulation
Abstraction -> 15th Concept
Abstraction – Hiding internal details or Hiding implementation or Hiding methods. Let’s take an example of a Car. When we drive a car, then the speed of Car will increase when we press accelrator, and the speed of the car will reduce when we press break. Now, we don’t know about the internal working of accelarator and break, so the internal details or the implementation of accelarator and break is hidden from us. This is called Abstraction.
Encapsulation -> 16th Concept
Encapsulation – If we have to create a laptop, then we need different different things like, Speaker, mother board, hard disc, RAM etc.. and all these different different things make a single entity laptop, but all these things like, Speaker, mother board, hard disc, RAM etc.. are combined together to form a single unit i.e. laptop. So, all these things like Speaker, mother board, hard disk etc. are encapsulated. This is the concept of Encapsulation.
So, Let’s take a look at all the concepts, that we are going to discuss as part of Object Oriented Programming in Javascript.
Before we understand object oriented programming, We must understand, why we do programming, and the answer to that question is, we do programming to make our life easy in real world.
So you take an example of Swiggy, Zomato, or a Camera in your mobile, or a clock in a mobile, all these things are software and softwares are created by programming. So, Programming makes our life easy. Same way, Object Oriented Programming makes programming easy. So, if some one asks us that why do we need object oriented programming, Can’t we do programming using functional programming only, then the answer is, We can work only with functional programming as well but Object Oriented Programming makes programming easy.
Now, one thing to note is that, We don’t use Object Oriented Programming in Javascript much, but we should know about Object Oriented Programming.
Objects, Classes and Constructor in Javascript Classes and Objects A class in any programming language…
Why we can not over ride a Constructor This is a very important question, that,…
What is Arrow Function In the last session, We had discussed about Anonymous Function. Anonymous…
What is Anonymous Function Anonymous Function is a type of function which has no name…
What is Map, Reduce and Filter Map Filter and Reduce are higher order methods for…
9 different ways of declaring or defining a function in Javascript In, one of our…