What is OOPs

10
0

Introduction

Object-Oriented Programming, commonly called OOP or OOPs, is a programming approach in which a program is organized around objects rather than only functions and instructions. These objects combine related data and the operations that can be performed on that data.

Class and Object

A class is a blueprint that defines properties and behaviours, while an object is an actual instance created from that class.

Basic Principles of OOPs

Object-oriented programming is mainly based on four principles:

Encapsulation

Encapsulation combines data and the methods that work on it within a single unit. It can also restrict direct access to certain data.

For example, a bank account can prevent users from directly changing its balance and provide methods for depositing or withdrawing money.

Encapsulation

Encapsulation

Abstraction

Abstraction displays only the necessary information while hiding internal implementation details.

For example, a person can drive a car using the steering wheel, brakes, and accelerator without understanding every internal part of the engine.

Abstraction

Abstraction

Inheritance

Inheritance allows one class to acquire properties and behaviours from another class. It supports code reuse and helps create relationships between classes.

For example, classes such as Car and Bike can inherit common features from a Vehicle class.

Inheritance

Inheritance

Polymorphism

Polymorphism means that the same operation can behave differently in different situations.

For example, a method named makeSound() may produce different results for a dog, cat, and bird.

Polymorphism

Polymorphism

Difference Between Procedural Programming and OOPs

Procedural programming organizes a program around functions or procedures, while object-oriented programming organizes it around objects.

Procedural Programming

Object-Oriented Programming

Program is divided into functions.

Program is divided into objects.

Follows a top-down approach.

Follows a bottom-up approach.

Provides limited data hiding.

Supports data hiding through encapsulation.

Provides limited code reusability through functions.

Provides greater reusability through inheritance and polymorphism.

Suitable for small and medium-sized programs.

Suitable for large and complex programs.

Examples: C, FORTRAN and Pascal

Examples: Java, C++, Python and C#

Advantages of OOPs

Object-oriented programming provides several benefits:

  • Modularity: A program can be divided into smaller components.

  • Reusability: Existing code can be reused in other parts of a program.

  • Maintainability: Changes can often be made without affecting the entire application.

  • Data security: Encapsulation can restrict unwanted access to data.

  • Scalability: New features can be added more easily as an application grows.

  • Clear structure: Related data and behaviours remain organized together.

OOPs advantage and use cases

OOPs advantage and use cases

Use Cases of OOPs

OOP is commonly used when software contains multiple entities with their own data and behaviour.

1. Banking Applications

Banking systems contain entities such as customers, accounts, loans, and transactions. OOP helps represent these entities and keeps their responsibilities organized.

2. E-Commerce Platforms

Online shopping systems contain products, customers, carts, orders, and payments. Each entity can be represented separately while still interacting with the others.

3. Game Development

Games contain players, enemies, weapons, vehicles, and other objects. OOP makes it easier to define their properties and behaviours.

4. Mobile Applications

Mobile apps use components such as screens, buttons, users, notifications, and services. Object-oriented programming helps developers manage these components.

CS Core

Read Similar Blogs

Comments0