Skip to main content

OOP Exercises

Blueprints into Real Systems

You’ve now mastered the four pillars of OOP: classes, inheritance, polymorphism, and encapsulation. But theory alone isn’t enough as you need to see how these concepts combine into real systems.

Imagine you’re a hacker building a library system to track books or an employee management system to organize staff. These projects show how OOP transforms abstract principles into working applications.


Why OOP Projects Matter

  • Integration: Combines all OOP pillars into cohesive systems.
  • Scalability: Real projects grow; OOP keeps them organized.
  • Reusability: Classes and inheritance prevent duplication.
  • Abstraction: Interfaces hide complexity, exposing only what’s necessary.
  • Real‑World Mapping: Systems mirror real entities like books, employees, users.

Library System

class Book:
    def __init__(self, title, author):
        self.title = title
        self.author = author
        self.is_available = True

    def borrow(self):
        if self.is_available:
            self.is_available = False
            print(f"You borrowed '{self.title}'.")
        else:
            print(f"'{self.title}' is not available.")

    def return_book(self):
        self.is_available = True
        print(f"You returned '{self.title}'.")

class Library:
    def __init__(self):
        self.books = []

    def add_book(self, book):
        self.books.append(book)

    def show_books(self):
        for book in self.books:
            status = "Available" if book.is_available else "Borrowed"
            print(f"{book.title} by {book.author} - {status}")
lib = Library()
b1 = Book("1984", "George Orwell")
b2 = Book("Python Mastery", "Shubham Sihasane")

lib.add_book(b1)
lib.add_book(b2)

lib.show_books()
b1.borrow()
lib.show_books()
b1.return_book()
lib.show_books()
  • Why? This system models books and their availability, showing encapsulation (is_available), methods, and object interactions.

Employee Management System

class Employee:
    def __init__(self, name, role):
        self.name = name
        self.role = role

    def work(self):
        print(f"{self.name} is working as {self.role}.")

class Manager(Employee):
    def work(self):
        print(f"{self.name} is managing the team.")

class Developer(Employee):
    def work(self):
        print(f"{self.name} is writing code.")

class Company:
    def __init__(self):
        self.employees = []

    def add_employee(self, employee):
        self.employees.append(employee)

    def show_employees(self):
        for emp in self.employees:
            emp.work()
company = Company()
m1 = Manager("Shubham")
d1 = Developer("Aditi")

company.add_employee(m1)
company.add_employee(d1)

company.show_employees()
  • Why? This system demonstrates inheritance (Manager and Developer extend Employee), polymorphism (work() behaves differently), and encapsulation (employee data managed inside Company).

The Hacker’s Notebook

  • Practical projects integrate all OOP pillars into real systems. The Library System models availability and borrowing with encapsulation.
  • The Employee Management System shows inheritance and polymorphism in action. Abstraction ensures users interact with clean interfaces (borrow(), work()) without worrying about internals.

Hacker’s Mindset: treat these projects as mini blueprints for larger systems. Today it’s a library or company; tomorrow it’s a CRM, ERP, or cloud service.


Tips, Tricks, Roadmaps, Resources, Networking, Motivation, Guidance, and Cool Stuff ♥

Updated on Jan 3, 2026