System Design ( Day - 33 )

Manoj KumarManoj Kumar
4 min read

OOPs Real-World Examples | Abstraction and Encapsulation

Let’s See the life of Developers before OOP’s

Firstly Machine language is introduced.( 1 / 0 )
The problem with the Machine language is its hard to write everything in 0’s and 1’s and prone to errors, it’s a tedious process, and also this is not Scalable.

Assembly level language
In this type they have introduced the writable letters instead of 0’s and 1’s, but in this also it prone to error, it’s tedious process, and this is not scalable at all.

Procedural programming
Everything is changed from here they have introduced the functions, loops, conditions and blocks, everything except objects, its like instructions to do the things like do this and then do this like set of instructions for us, this is how the procedural programming happening, this can solve the problems but at small level, when we are talking about large application like enterprise application they need something better than this, that’s when they introduced OOP’s

Why we are shifted from procedural to oops let’s deep dive into it.
1. Procedural programming is lagging at the place of Modelling to real world. like everything should be modelled as real world.
2. Data security
3. Highly scalable and reusable code.

Why OOP’s ?
In this world everything is objects me, you and your mobile, laptop everything is object and we are interacting with the objects
how we can implement this in programming, With Characteristics and Behaviour in the programming space those are variables and Functions variables are capable of staring the characteristics of the object and the functions are there to show the behaviour of the object.
in the procedural programming the code reusability is the main issue, in which by using the oops that is easily possible.

Pillars of OOPS
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism

Abstraction
In simple words, let’s say you are watching the TV, is it necessary to know the internal working of the TV to watch it, like how images and videos are displayed what are the components inside that TV, No we don’t need to know these things to watch the TV what we need is a Remote which helps to control the TV, just we need to press the buttons in it and we’re done, those things are hidden inside it and we don’t need to know all the things right in a same way with the objects also we just need to call the functions and and do our calculations, we don’t need to know that. like Remote, when you press power button in remote it will trigger function which is not visible to us or we don’ t need to know how its running, what we need is when we press power button it should power on the TV that’s it. That’s Abstraction.
Abstraction hides unnecessary details from the Client that is Abstraction.

Encapsulation
In Simple words, in above abstraction example we have seen the Characteristics and Behaviour which is variables and functions, binding those things in a one place is nothing but encapsulation in the programming terms its a class (class is nothing but a blueprint), in those class we can write the variables and functions which is encapsulated to form the final object. and it also talks about the data security, there are some variables that are restricted, so that that can’t be changed from outside of the class like, if you have smart TV then we can’t change the software of the tv and we can’t change the functionality of the buttons also those things are handled by the access modifiers. those are Public, private and Protected.
Public: In Tv we can change the time of the clock present in that and we can change the resolution also those are public access modifiers. in which the things can be changed easily.
Private: We can’t change the TV’s software directly right that is private, in which things that are not accessible to everyone those things are called as Private access modifiers.
Protected: This one is like we can access but with some canstraint’s like if we set a password to any folder, without the password the things present in that folder are not accessible for everyone.

0
Subscribe to my newsletter

Read articles from Manoj Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Manoj Kumar
Manoj Kumar