Four Pillars of Object Oriented Programming (OOP) : 1. What Is Abstraction?
Four Pillars of Object Oriented Programming (OOP) : 1. What Is Abstraction?
(OOP)
Abstraction
Encapsulation
Inheritance
Polymorphism
1. What is Abstraction?
1. In figure (A): When you want to book a ride, you have to Enter
a pick-up point.
3. In figure (C): After done with typing the destination place now you
have to select a place from the suggestion list.
4. In figure (D): After done with selecting one from the suggestion list,
you found your estimation of time and cost.
What interesting about each point is you do all your actions with just one touch
and you don’t need to worry about how its happening like when you touched on
Enter a pickup point then how the map is opened and how that pointer points to
your location? Did you need to know that? What you concern about at that point
was to locate my location correctly, and that’s it! and that’s exactly what Uber
App doing for you (i.e. information hiding).
2. What is Encapsulation?
Lets try to understand it. Let’s say we have a class called Mobile and we have
some public functions (public means the function can be called outside from the
class) :
openCamera()
openClock()
openCalender()
openMaps()
openNotes()
openAppStore()
and so on. Above figure shows the comparison of mobile phone with a camera
feature (middle one) and another mobile phone with a camera feature including a
further feature of zoom in (right one). Let’s talk about openCamera() function.
Initially you just have a function which opens camera for you! nothing else. Then
you have got a new idea in a shape of (Zoom in) feature. To implement this idea
you only have to update your OpenCamera() function. The point that needs to
understand here is you don’t need to worry about anything outside of this
function. You just go to the function, make some changes and BOOM!. That is
what Encapsulation offers you (the mechanism of implementing class and
function and making things together).
2. What is Inheritance?
Single Inheritance
Multi-level Inheritance
Multiple Inheritance
Hierarchical Inheritance
In this type of inheritance, a child class inherits the behavior from parent class so
in above example, child class is GroupCall class which inherits the behaviors (i.e.
startAudioCall() and startVideoCall()) from parent class i.e. Call. The point that
needs to understand here that instead of defining those method (i.e.
startAudioCall() and startVideoCall()) again in GroupCall class, those methods
will be inherited from the parent class. So in this way inheritance is done!
2. Multi-level Inheritance:
4. Hierarchical Inheritance:
4. What is Polymorphism?