C# एक पूरी तरह से OOP language है।
अगर OOP समझ गए, तो आप Web APIs, Desktop Software, Mobile Apps, Games, ERP Systems—कुछ भी आसानी से बना सकते हो।
इस blog में OOP को इतना आसान बनाऊँगा कि एक बार पढ़कर दिमाग में बैठ जाएगा।
OOP का मतलब है—
Objects (चीज़ें), उनके data और उनके behavior को एक structure में रखना।
जैसे real life में हर चीज़ एक object है—
Car
Mobile
Person
Bank Account
वैसे ही software में भी हम सबको objects की तरह represent करते हैं।
Data + Functions = Class
ये चीज़ों को एक box में बाँध देता है।
Mobile का volume system:
Volume up/down button अंदर एक code को call करता है
लेकिन actual volume data hidden रहता है
User सिर्फ button दबाता है — अंदर कैसे चलता है, ये छुपा होता है।
class BankAccount
{
private double balance; // hidden
public void Deposit(double amount)
{
balance += amount;
}
}
Parent class से child class को features मिलते हैं।
Car (parent)
↓
SportsCar, ElectricCar, SUV (child)
सभी में steering, engine, wheels common होंगे।
class Vehicle
{
public int Wheels = 4;
}
class Car : Vehicle
{
public string Model = "Swift";
}
Mobile का camera button—
Photo mode → फोटो लेता है
Video mode → वीडियो रिकॉर्ड
Portrait mode → background blur
एक button, कई काम।
class Printer
{
public virtual void Print()
{
Console.WriteLine("Printing...");
}
}
class ColorPrinter : Printer
{
public override void Print()
{
Console.WriteLine("Color Printing...");
}
}
User को सिर्फ ज़रूरी चीज़ें दिखाना।
ATM machine:
User बस amount दर्ज करता है
अंदर notes कैसे निकलते हैं, कैसे reduce होते हैं → hidden
abstract class Shape
{
public abstract double Area();
}
class Circle : Shape
{
public override double Area()
{
return 3.14 * 5 * 5;
}
}
आपने बताया था कि आप G17 / S15 GPS devices का server C# में बना रहे हो।
GPS system पूरा OOP पर चलता है।
class Device
{
public string IMEI { get; set; }
public DateTime LastUpdated { get; set; }
}
class G17 : Device
{
public double Latitude { get; set; }
public double Longitude { get; set; }
}
class S15 : Device
{
public int Battery { get; set; }
}
Device → Parent class
G17, S15 → Child classes
हर model के अपने unique features
यही OOP की ताकत है —
हर GPS device का अलग data, behavior लेकिन एक ही structure।
OOP सीखने के बाद C# आपकी superpower बन जाता है।
Large projects, APIs, Billing software, ERP, Games—सब OOP से बनते हैं।
0 Comments
Thanks for Commenting on our blogs, we will revert back with answer of your query.
EmojiThanks & Regards
Sonu Yadav