Lesson Plan: Object-Oriented Programming (OOP) in Python
Objective:
By the end of this lesson, students will:
● Understand the core principles of Object-Oriented Programming (OOP).
● Learn how to create and use classes and objects.
● Apply OOP concepts in a real-world project.
1. What is Object-Oriented Programming (OOP)?
OOP is a programming paradigm that uses objects and classes to structure code in a more
organized way.
Benefits of OOP:
✅ Reusability (Write once, use multiple times)
✅ Easy to maintain and modify code
✅ Organizes complex programs into simpler components
2. Key OOP Concepts
1️⃣ Classes and Objects
● Class: A blueprint for creating objects.
● Object: An instance of a class.
Example:
class Animal:
def __init__(self, name, sound):
[Link] = name
[Link] = sound
def make_sound(self):
print([Link] + " says " + [Link])
cat = Animal("Cat", "Meow")
dog = Animal("Dog", "Woof")
cat.make_sound()
dog.make_sound()
2️⃣ Encapsulation
Encapsulation is the practice of keeping data safe by making variables private.
Example:
class BankAccount:
def __init__(self, balance):
self.__balance = balance # Private variable
def deposit(self, amount):
self.__balance += amount
def get_balance(self):
return self.__balance
account = BankAccount(1000)
[Link](500)
print(account.get_balance()) # Output: 1500
3️⃣ Inheritance
Inheritance allows a class to inherit attributes and methods from another class.
Example:
class Vehicle:
def __init__(self, brand):
[Link] = brand
def honk(self):
print("Honk! Honk!")
class Car(Vehicle):
def __init__(self, brand, model):
super().__init__(brand)
[Link] = model
car = Car("Toyota", "Corolla")
print([Link], [Link])
[Link]()
4️⃣ Polymorphism
Polymorphism allows different classes to use the same method name with different
implementations.
Example:
class Bird:
def sound(self):
print("Chirp Chirp")
class Dog:
def sound(self):
print("Bark Bark")
def make_sound(animal):
[Link]()
bird = Bird()
dog = Dog()
make_sound(bird)
make_sound(dog)
Project: Simple Library Management System
Students will build a program to manage a small library using OOP concepts.
Features:
● Add new books
● Borrow books
● Return books
Code:
class Book:
def __init__(self, title, author):
[Link] = title
[Link] = author
[Link] = True
def borrow(self):
if [Link]:
[Link] = False
print(f"You borrowed '{[Link]}'")
else:
print(f"Sorry, '{[Link]}' is not available.")
def return_book(self):
[Link] = True
print(f"You returned '{[Link]}'")
class Library:
def __init__(self):
[Link] = []
def add_book(self, book):
[Link](book)
print(f"Book '{[Link]}' added to the library.")
def show_books(self):
print("Available books:")
for book in [Link]:
status = "Available" if [Link] else "Borrowed"
print(f"{[Link]} by {[Link]} - {status}")
# Example usage
lib = Library()
book1 = Book("Harry Potter", "J.K. Rowling")
book2 = Book("The Hobbit", "J.R.R. Tolkien")
lib.add_book(book1)
lib.add_book(book2)
lib.show_books()
[Link]()
lib.show_books()
book1.return_book()
lib.show_books()
Learning Outcomes:
✅ Using classes and objects to structure programs
✅ Implementing encapsulation to protect data
✅ Using inheritance to reuse code
✅ Applying polymorphism for flexibility
✅ Building a real-world Library Management System
Recap:
● Classes & Objects help create reusable components.
● Encapsulation secures data.
● Inheritance enables code reusability.
● Polymorphism allows flexibility.
● Project application strengthens OOP concepts!
This lesson makes learning OOP fun and practical with an engaging project!