Object-Oriented Programming

Gautam Gandhi
3 min readMay 9, 2021

OOPS -

By OOPs we mean a language that uses classes and objects in programming.

Classes-

Every website says — “ Classes are the blueprint of an object.” Blueprint in simple words means a design.

The class contains characteristics/ features and attributes.

  • Attributes:

Can you imagine any characteristics of a human being?

  1. Height
  2. Weight
  3. Gender
  4. Name
  5. Age

So these are all attributes of a class of human beings.

  • Functions:

Can you imagine any function of a human being?

Eating, Sleeping, Any other hobby(Swimming, dancing, etc …….)

So these are all the functions performed by a human being.

Objects:

Every website also says: “Object is an instance of a class”.

So what does instance mean?

We have discussed class as a blueprint. Instance means an example or single occurrence of something.

So now map objects with real-world entities.

Let’s say my name is “XYZ” and I am also a human being. So my attributes would be

  1. Height: 6’4
  2. Weight: 65 kg
  3. Gender: Male
  4. Name: XYZ
  5. Age: 30

So XYZ is an instance of a class “HumanBeing”.

Features of OOPS:

  1. Abstraction-
  • In simple terms, “Abstraction deals with the complexity of data”.
  • Consider a real-life example of Gmail. We all use Gmail or other mail services OK, but can you tell us how does mail work?
  • Can you tell which mail sending protocol POP3, SMTP, IMAP, etc is used when the email is sent?
  • I know most of us have heard these words for the first time. So abstraction means hiding implementation details and showing all the functionality related to all the uses.

2. Encapsulation-

  • It is defined as “Wrapping up of data”. Every book/website says that in general.
  • It is a mechanism that binds together code and data.
  • Real-life example — Consider a protective shield that prevents the data from being accessed by the code outside this shield.

3. Inheritance-

  • It refers to the ability of one class to inherit the features (methods and data) of the parent class.
  • Real-life example: Whenever our relatives come to our house they say you resemble your mother or father. Does this happen to you?

This is called Inheritance.

Types of inheritance:

  • Single level
  • Multi-level
  • Hierarchical
  • Multiple
  • Hybrid

4. Polymorphism-

  • It means having “many forms”.
  • Real-life example: A person at the same time can have different roles like a man at the same time can be a father, employee, husband, son, etc all at the same time.

That’s called “Polymorphism”.

Types of polymorphism:

  • Compile-time
  • Runtime

--

--