Learn OOP concept

Learn OOP concept

Learn in easy language

All the modern programming languages are based on Object Orientation i.e. writing programs that have emphasis on real life applications. This article will teach you the concepts using real life examples and illustration.

Classes & Objects

A class is a blueprint of an object, it defines the structure and functioning of an object — Yeah, this is the most common definition that you’ll read but it fails to explain what exactly is blueprint, working and structure means? Let’s understand them with an analogy.

We have a building as an object, if we have to build a structure the first thing we need is a blueprint or an architectural map (as seen in the diagram). This is why a class is called as blueprint of the object, because it defines its structure. Can you make a building without having a blueprint? No, right? Similarly without class there can be no object. An object is an instance of a class.

Screenshot_2022-09-16-12-21-21-837-edit_com.medium.reader.jpg

  • Blueprint (The Class) → Tells the
  • Builder (The Compiler) → To make
  • The building (Object)

Screenshot_2022-09-16-12-21-44-889-edit_com.medium.reader.jpg

Abstraction

Abstraction is a practice of hiding the complexity in a system and giving the user a graphical interface to complete the intended task. When you go to a bank to withdraw or deposit money are you concerned about what’s happening at the back? Mostly not, we only focus on the service. Hence, in OOP languages we programmers are expected to design systems that the end user can easily operate.

Screenshot_2022-09-16-12-25-40-125-edit_com.medium.reader.jpg

Encapsulation

In a program the data members and methods are tied together in a class like a capsule. The data and methods are not accessible outside the class unless it’s inherited. Like how only your family members will have the key of your house, it won’t be accessible for any stranger.

Screenshot_2022-09-16-12-25-54-450-edit_com.medium.reader.jpg

Inheritance

When a method or a class inherits some properties of any other class above its hierarchy, it’s called inheritance. The inherited class is called the derived class/child class and the other one is called as the base class/parent class. Dogs and Lions both are animals that share the same properties of having four legs while they both are independently have some unique features (Bread and Ability)

Screenshot_2022-09-16-12-26-09-630-edit_com.medium.reader.jpg

Polymorphism

Morphism means being in a state or a structure, poly means many. So, polymorphism is when something can take multiple forms. If you are a student, imagine your daily routine. You perform different actions under different situation. Playing sports in ground, studying in university or doing work. Correspondingly in a program same method can perform different function when called under different conditions. It helps avoid writing the same method again and again.

Screenshot_2022-09-16-12-26-22-278-edit_com.medium.reader.jpg

Hope it was worth your time!

Any questions? Follow me On Twitter and LinkedIn