Object Oriented Programming : अवधारणाएँ, विशेषताएँ व उदाहरण

Object-Oriented Programming

Object-Oriented Programming (OOPs) एक programming paradigm है, जिसमें programs को objects और classes के रूप में design किया जाता है।

Object = real-world entity (जैसे Student, Bank Account)
Class = blueprint/template (objects बनाने का ढांचा)

OOPs का use C++, Java, Python, C# जैसी modern programming languages में होता है।

Example (Flipkart):

  • Object = Customer, Product, Cart, Order
  • Class = Blueprint जिसमें Customer Details, Product Details, Payment Methods आदि Defined होते हैं।

हर Object Data और उस Data पर Perform होने वाले Operations दोनों को Represent करता है।

Structure (सामान्य Flow)

#include <iostream>
using namespace std;
class Student {
public:
string name;
int age;
void show() {
cout << “Name: ” << name << “, Age: ” << age;
}
};
int main() {
Student s1;
s1.name = “Aman”;
s1.age = 20;
s1.show();
return 0;
}

Features of OOP (विशेषताएँ)

  • Bottom-up Approach : Design Objects से शुरू होकर पूरे Program तक जाता है।
  • Encapsulation (Data + Functions Together) : Data और Functions को एक Unit (Class) में Bind किया जाता है।
  • Inheritance : Existing Class से New Class बनाई जा सकती है।
  • Polymorphism : एक Function या Operator Different Behaviors Show कर सकता है।
  • Abstraction : केवल Necessary Details User को Show होती हैं, बाकी Hide रहती हैं।
  • Data Security High : Data को Directly Access नहीं किया जा सकता।

Concepts (अवधारणाएँ)

1. Class (क्लास)

Class एक blueprint या template है जिससे objects बनाए जाते हैं।
इसमें attributes (data members) और methods (functions) होते हैं।

Example: आपको “Student” बनाना है, तो पहले आप Student नाम की class बनाएंगे, जिसमें rollNo, name, marks जैसे attributes होंगे और study(), giveExam() जैसे methods होंगे।

class Student {
public:
int rollNo;
string name;
void study() {
cout << “Student is studying”;
}
};

2. Object (ऑब्जेक्ट)

Object एक real-world entity है जो class से create होती है। Object के पास state (attributes) और behavior (methods) होते हैं।

Example: Student class से आप Student s1; object बना सकते हैं।

Student s1; // Object s1 created from class Student
s1.rollNo = 101;
s1.name = “Amit”;
s1.study();

3. Inheritance (इनहेरिटेंस)

Inheritance वह process है जिसमें एक class (child/derived class) दूसरी class (parent/base class) की properties (data members) और behaviors (methods) को inherit (अवगत) करती है। Code reusability के लिए use किया जाता है।

Example: ISRO में Satellite एक parent class हो सकती है और CommunicationSatellite, WeatherSatellite child classes।

4. Polymorphism (पॉलीमॉर्फ़िज़्म)

Polymorphism का मतलब होता है – “एक ही चीज़ कई रूपों (forms) में काम कर सकती है।”
Programming में इसका use code को flexible और re-usable बनाने के लिए किया जाता है।

दो प्रकार:
Compile-Time Polymorphism → Function/Operator Overloading
Run-Time Polymorphism → Method Overriding

Example: एक व्यक्ति पिता, बेटा और कर्मचारी – अलग-अलग roles play कर सकता है।

5. Abstraction (एब्स्ट्रैक्शन)

Abstraction वह concept है जिसमें programmer system की essential features दिखाता है और non-essential/internal details को hide कर देता है।

Example: जब आप Paytm से recharge करते हैं, आपको सिर्फ “Recharge Successful” दिखता है, backend API calls और servers hidden रहते हैं।

6. Encapsulation (एनकैप्सुलेशन)

Encapsulation, Object-Oriented Programming का वह concept है जिसमें class के अंदर attributes और methods को एक unit में रखा जाता है और उनकी accessibility को control किया जाता है। यह concept Data Hiding को भी support करता है।
Example: ATM card – PIN और balance को direct access नहीं कर सकते, केवल authorized methods (withdraw, deposit) से ही काम होगा।

Advantages (लाभ)

  1. High Data Security (उच्च डेटा सुरक्षा)
  2. Code Reusability (कोड की पुन:उपयोग क्षमता)
  3. Easy Software Maintenance (सॉफ्टवेयर रखरखाव आसान)
  4. Best Approach for Large Projects (बड़ी परियोजनाओं के लिए सर्वोत्तम दृष्टिकोण)
  5. Real-World Modeling Possible (वास्तविक दुनिया का मॉडल बनाना संभव)
  6. Scalability & Extensibility (स्केलेबिलिटी और एक्स्टेंडेबिलिटी)

Limitations (सीमाएँ)

  • Complex Structure (शुरुआती लोगों के लिए मुश्किल)
  • Execution Speed कभी-कभी धीमी होती है
  • छोटे प्रोग्रामों के लिए Overhead Create करता है
error: Content is protected !!