OOPs Concepts | Object Oriented Programming

OOP cconepts are the most fundamental concepts in programming languages like Java, Python, Javascript, etc.

Here's a Dead Simple Guide to Understand It:

There are six different concepts in OOP:

  • Object
  • Class
  • Inheritance
  • Encapsulation
  • Abstraction
  • Polymorphism

oops-concepts-object-oriented-programming

1. Object

Every real-world entity is an object.

An object has Behaviour (things it does or performs) and Attributes (things that describe it).

For eg: A Chair object can have behavior like Movement, Height Adjustment  & Attributes like Color, Make & Model, and Price.

2. Class

The collection of all related objects is called a class.

Consider class as a general category that contains all the related objects inside it.

For eg: Objects like a Wheelchair, Office Chair, and Wooden Chair can be a part of the "Chair" class.

3. Inheritance

The way we inherited a few qualities from our parents similarly, a class can also inherit the qualities from a parent class.

For eg: A Phone Class can have two Child Classes: 1) TelePhone and 2) MobilePhone. Both can inherit the "calling" behavior.

4. Encapsulation

It means wrapping data into a single unit & securing it.

For eg: Drug Capsule wraps different medicines into a single unit and protects them from the outside environment.

Bank Locker wraps your valuables into a single unit(locker) and protects it via passcode.

5. Abstraction

Hiding complexity from the user and showing only the relative stuff.

For Eg: In a Car, all the complexity like the engine, machinery, etc is hidden from you; only relevant parts are shown, like the brakes, accelerator, and gearbox.

6. Polymorphism

It means many forms. With the same name, it provides different forms.

For eg: In Chess, we've 6 pieces - king, rook, bishop, queen, knight, and pawn. All of them "move" differently i.e. Bishop moves diagonally, Rooks moves horizontally and vertically, etc.

oop-conepts-fundamental-concepts-programming-languages

All Chess piece performs a common behavior "move" but they all do it differently.

The behavior name "move" is the same but it's still differently done by different Objects.

LOADING