Python में ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग
Alex Yarosh
Content Quality Analyst @ DataCamp

# Withdraw amount from each of accounts in list_of_accounts def batch_withdraw(list_of_accounts, amount): for acct in list_of_accounts: acct.withdraw(amount)b, c, s = BankAccount(1000), CheckingAccount(2000), SavingsAccount(3000) batch_withdraw([b,c,s]) # <-- Will use BankAccount.withdraw(), # then CheckingAccount.withdraw(), # then SavingsAccount.withdraw()
batch_withdraw() को यह जाँचने की ज़रूरत नहीं कि किस ऑब्जेक्ट पर कौन सा withdraw() कॉल करना है
बेस क्लास को उसकी किसी भी सबक्लास से बदला जा सके, और प्रोग्राम के गुण न बदलें
जहाँ भी BankAccount काम करता है, वहाँ CheckingAccount भी काम करना चाहिए

बेस क्लास को उसकी किसी भी सबक्लास से बदला जा सके, और प्रोग्राम के गुण न बदलें
→ Syntactic incompatibility
BankAccount.withdraw() 1 पैरामीटर लेता है, लेकिन CheckingAccount.withdraw() 2 लेता है
→ Subclass strengthening input conditions
BankAccount.withdraw() कोई भी amount लेता है, लेकिन CheckingAccount.withdraw() मानता है कि amount सीमित है
→ Subclass weakening output conditions
BankAccount.withdraw() या तो बैलेंस पॉज़िटिव छोड़ता है या error देता है, CheckingAccount.withdraw() बैलेंस नेगेटिव छोड़ सकता है
→ सबक्लास के मेथड में अतिरिक्त attributes बदलना
→ सबक्लास के मेथड में अतिरिक्त exceptions फेंकना
$$\text{\textbf{\Huge{No LSP -- No Inheritance}}}$$
Python में ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग