Author: Muhammad Aryan
Date: May 19, 2025
Assignment Name: Python Object-Oriented Programming (OOP) – Core Principles & Applications
Objective: Grasp the essence of OOP in Python through 21 practical, real-world examples and concepts.
Create a Student class with name and marks, initialized via self in the constructor. Includes display() method.
Implement a Counter class with a class variable. Use @classmethod to track and display number of instances.
Build a Car class with a public variable brand and public method start(). Show how to access both from outside.
Create a Bank class with a class variable bank_name. Add change_bank_name() using @classmethod to update it.
Create MathUtils with a static method add(a, b) to return the sum of two numbers.
Design a Logger class that prints messages when an instance is created and destroyed.
In Employee, demonstrate:
name(public)_salary(protected)__ssn(private, accessed via name mangling)
Create a Person class with a constructor. Subclass Teacher uses super() to inherit and extend functionality with subject.
Use abc.ABC to create an abstract Shape class with area(). Implement it in Rectangle.
Build a Book class with a class variable total_books. Use @classmethod to increment the count.
Create TemperatureConverter with a static method to convert Celsius to Fahrenheit.
Use Car and Engine classes to demonstrate composition—Engine object exists within Car.
Use Department and Employee to model aggregation—a Department holds Employee references.
Build a diamond inheritance structure: A, B, C, and D(B, C). Show method resolution using __mro__.
Write a function decorator log_function_call that announces when a function is being called.
Create a class decorator add_greeting that dynamically injects a greet() method into the class.
Define a Product class with private _price and use property decorators to manage access and deletion.
Create a Multiplier class with a __call__() method, enabling objects to be used like functions.
Implement InvalidAgeError and raise it in check_age(age) if age < 18. Use try-except to handle it.
Build a Countdown class that implements __iter__() and __next__() to count down from a start value to 0.
A review-worthy final structure demonstrating every aspect of OOP in an integrated and interconnected way. This includes:
- Clean object instantiation
- Property decorators
- MRO logic
- Decorators (function/class)
- Custom exceptions
- Composition and Aggregation
- Clone the repository:
git clone https://github.com/yourusername/python-oop-mastery.git
cd python-oop-mastery