ITDarasgah Certified Python Developer
📘 Lecture 10: Object Oriented Programming (OOP)
📌 لیکچر کے مقاصد
اس لیکچر کے اختتام پر آپ:
Object Oriented Programming کا بنیادی تصور سمجھیں گے
class اور object بنا سکیں گے
attributes اور methods استعمال کریں گے
inheritance اور encapsulation کا تعارف حاصل کریں گے
🔹 OOP کیا ہے؟
Object Oriented Programming ایک programming paradigm ہے جس میں پروگرام کو objects کی صورت میں منظم کیا جاتا ہے۔
Real-world مثال:
Car → ایک object
Color, Model → attributes
Drive(), Brake() → methods
🔹 Class کیا ہوتی ہے؟
Class ایک blueprint ہوتی ہے جس سے objects بنائے جاتے ہیں۔
class Student:
pass
🔹 Object کیا ہوتا ہے؟
Object class کا ایک instance ہوتا ہے۔
s1 = Student()
print(s1)
🔹 Attributes اور init method
class Student:
def __init__(self, name, marks):
self.name = name
self.marks = marks
s1 = Student("Ali", 85)
print(s1.name, s1.marks)
🔹 Methods
class Student:
def display(self):
print(f"Name: {self.name}, Marks: {self.marks}")
s1.display()
🔹 Multiple Objects
s2 = Student("Sara", 92)
s2.display()
🔹 Inheritance (وراثت)
class Person:
def __init__(self, name):
self.name = name
class Student(Person):
def __init__(self, name, marks):
super().__init__(name)
self.marks = marks
🔹 Encapsulation (Basic)
class BankAccount:
def __init__(self, balance):
self._balance = balance
def show_balance(self):
print(self._balance)
📌 _balance ایک protected attribute کی مثال ہے۔
🔹 OOP کے فائدے
Code reusable ہوتا ہے
Programs منظم ہوتے ہیں
Large systems بنانے میں آسانی
📝 Assignment – Lecture 10
🔸 Mini Project: Bank Account System
Requirements:
Account holder name
balance attribute
deposit() اور withdraw() methods
balance show کرنے کا method
📌 Bonus:
inheritance استعمال کریں (SavingAccount)
📌 Assignment فورم پر code block میں پوسٹ کریں۔
💬 Discussion Prompt
OOP کے بغیر اور OOP کے ساتھ code میں کیا فرق محسوس ہوا؟
inheritance کہاں واقعی فائدہ مند ہے؟
📌 اگلا لیکچر: Python Libraries – NumPy & Pandas

کوئی تبصرے نہیں:
ایک تبصرہ شائع کریں