Welcome back, programmer! You have come a long way. In Module One, you learned what Object Oriented Programming is. You learned about objects and classes. In Module Two, you learned how to write classes and create objects in Python. In Module Three, you learned about inheritance and polymorphism. In Module Four, you learned about encapsulation and abstraction.
Now it is time to put everything together. In this module, you will build a complete program using all the ideas you have learned. You will create classes. You will use inheritance. You will use polymorphism. You will protect data with encapsulation. You will simplify with abstraction.
We will build a School Management System. It will have students, teachers, and courses. It will show how OOP makes programs organised and powerful. By the end, you will have a complete program that you can run and be proud of.
We will keep using simple words and lots of examples. Letβs build something amazing!
After you finish this module, you will be able to:
Emeka lived in Abuja. His school had just received new computers. The principal asked Emeka to help create a program to manage student information. Emeka was excited. He had learned about OOP and wanted to use it.
He started by thinking about what a school has. A school has students. A school has teachers. A school has courses. Each of these is an object.
Emeka created a class called Person. It had a name and an age. Then he created a class called Student that inherited from Person. A student also has a class level and scores. Then he created a class called Teacher that also inherited from Person. A teacher also has a subject and a salary.
He used encapsulation to protect the studentβs scores. He used abstraction to create a common blueprint for all people. He used polymorphism so that both students and teachers could introduce themselves in their own way.
When he finished, he showed the program to his principal. The principal was amazed. βThis program can manage hundreds of students and teachers,β she said. βYou have built something truly useful.β
Emeka smiled. He had learned that OOP is not just about writing code. It is about solving real problems in an organised way.
Moral of the story: OOP helps you build big programs by organising them into small, manageable objects.
Definition: The four pillars of OOP are encapsulation, abstraction, inheritance, and polymorphism.
Why it is important: These are the foundation of all OOP programs.
Simple explanation: Think of a house. Encapsulation is the walls. Abstraction is the door. Inheritance is the foundation. Polymorphism is the rooms that serve different purposes.
Real-life example: A car uses all four pillars. Encapsulation protects the engine. Abstraction hides the engine. Inheritance makes different car models from one design. Polymorphism makes different cars move differently.
School example: A school uses all four pillars. Encapsulation protects student records. Abstraction shows only the timetable. Inheritance creates different types of students. Polymorphism makes different students study differently.
Home example: A kitchen uses all four pillars. Encapsulation protects the fridge. Abstraction hides the cooking process. Inheritance creates different appliances from one design. Polymorphism makes different appliances work differently.
Nigerian example: A market uses all four pillars. Encapsulation protects the goods. Abstraction shows only the prices. Inheritance creates different types of traders. Polymorphism makes different traders sell differently.
Table: The Four Pillars
| Pillar | What it does | Example |
|---|---|---|
| Encapsulation | Protects data | Private bank balance |
| Abstraction | Hides complexity | Car steering wheel |
| Inheritance | Reuses code | Dog inherits Animal |
| Polymorphism | Many forms | Dog barks, Cat meows |
Mini summary: The four pillars of OOP are encapsulation, abstraction, inheritance, and polymorphism. They work together to make programs organised and powerful.
Definition: Planning means deciding what classes you need and what they will do.
Why it is important: A good plan saves time and prevents confusion.
Simple explanation: Before you write code, think about the objects in your program. What are they? What data do they have? What actions can they do?
Real-life example: Before building a house, you draw a plan.
School example: Before writing an essay, you make an outline.
Home example: Before cooking, you gather ingredients.
Nigerian example: Before sewing a dress, you take measurements.
Illustration:
Plan Your Program
|
V
What objects do I need?
|
V
What data do they have?
|
V
What actions can they do?
|
V
Start Coding!
Mini summary: Planning means deciding what classes you need. Think before you code.
Definition: A parent class holds common attributes and methods that child classes will share.
Why it is important: It saves time and keeps code organised.
Simple explanation: Both students and teachers are people. They both have names and ages. They both can introduce themselves. So we create a Person class.
Real-life example: All people have names and ages.
School example: All members of a school have names and ages.
Home example: All family members have names and ages.
Nigerian example: All Nigerians have names and ages.
Example code:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def introduce(self):
print("Hello, my name is " + self.name + " and I am " + str(self.age) + " years old.")
Illustration:
class Person:
__init__ -> name, age
introduce() -> "Hello, my name is..."
Mini summary: The Person class holds common data and actions for all people.
Definition: A student is a person who studies. The Student class inherits from Person.
Why it is important: Students have special data (class level, scores) and special actions (study, take exam).
Simple explanation: The Student class gets name and age from Person. It adds class level and scores.
Real-life example: A student has a name, age, class, and scores.
School example: A student in JSS3 has scores in different subjects.
Home example: A child in school has homework and test scores.
Nigerian example: A student in a Nigerian school takes WAEC exams.
Example code:
class Student(Person):
def __init__(self, name, age, class_level):
super().__init__(name, age)
self.class_level = class_level
self.__scores = []
def add_score(self, score):
if 0 <= score <= 100:
self.__scores.append(score)
else:
print("Error: Score must be between 0 and 100.")
def get_average(self):
if len(self.__scores) == 0:
return 0
return sum(self.__scores) / len(self.__scores)
def study(self):
print(self.name + " is studying.")
def introduce(self):
super().introduce()
print("I am in " + self.class_level + ".")
Illustration:
class Student(Person):
__init__ -> name, age, class_level, __scores
add_score() -> adds a score safely
get_average() -> returns average
study() -> "studying"
introduce() -> calls parent + "I am in JSS3"
Mini summary: The Student class inherits from Person. It adds class level, scores, and study methods.
Definition: A teacher is a person who teaches. The Teacher class inherits from Person.
Why it is important: Teachers have special data (subject, salary) and special actions (teach, mark).
Simple explanation: The Teacher class gets name and age from Person. It adds subject and salary.
Real-life example: A teacher has a name, age, subject, and salary.
School example: A maths teacher teaches maths and marks exams.
Home example: A private tutor teaches at home.
Nigerian example: A teacher in a Nigerian school prepares students for exams.
Example code:
class Teacher(Person):
def __init__(self, name, age, subject, salary):
super().__init__(name, age)
self.subject = subject
self.__salary = salary
@property
def salary(self):
return self.__salary
@salary.setter
def salary(self, amount):
if amount > 0:
self.__salary = amount
else:
print("Error: Salary must be positive.")
def teach(self):
print(self.name + " is teaching " + self.subject + ".")
def introduce(self):
super().introduce()
print("I teach " + self.subject + ".")
Illustration:
class Teacher(Person):
__init__ -> name, age, subject, __salary
salary (property) -> getter and setter
teach() -> "teaching"
introduce() -> calls parent + "I teach Maths"
Mini summary: The Teacher class inherits from Person. It adds subject, salary, and teach methods.
Definition: A course is a subject that students take and teachers teach.
Why it is important: Courses connect students and teachers.
Simple explanation: A course has a name, a teacher, and a list of students.
Real-life example: A maths course has a teacher and many students.
School example: JSS3 Maths is a course with Mr Bello and 30 students.
Home example: A cooking class has a teacher and students.
Nigerian example: A WAEC preparation course has a teacher and students.
Example code:
class Course:
def __init__(self, name, teacher):
self.name = name
self.teacher = teacher
self.students = []
def add_student(self, student):
self.students.append(student)
print(student.name + " has been added to " + self.name + ".")
def show_details(self):
print("Course: " + self.name)
print("Teacher: " + self.teacher.name)
print("Students: " + str(len(self.students)))
Illustration:
class Course:
__init__ -> name, teacher, students
add_student() -> adds a student
show_details() -> prints course info
Mini summary: The Course class connects students and teachers. It has a name, a teacher, and a list of students.
Definition: Inheritance lets Student and Teacher share code from Person. Polymorphism lets them introduce themselves differently.
Why it is important: It makes the program flexible and organised.
Simple explanation: Both students and teachers can introduce themselves. But students say βI am in JSS3β and teachers say βI teach Mathsβ.
Real-life example: Both doctors and nurses are people. They introduce themselves differently.
School example: Both students and teachers are people. They introduce themselves differently.
Home example: Both children and parents are people. They introduce themselves differently.
Nigerian example: Both traders and customers are people. They introduce themselves differently.
Example code:
people = [
Student("Ada", 14, "JSS3"),
Teacher("Mr Bello", 35, "Maths", 150000),
Student("Tunde", 15, "JSS2"),
Teacher("Mrs Okafor", 40, "English", 180000)
]
for person in people:
person.introduce()
print("---")
Output:
Hello, my name is Ada and I am 14 years old. I am in JSS3. --- Hello, my name is Mr Bello and I am 35 years old. I teach Maths. --- Hello, my name is Tunde and I am 15 years old. I am in JSS2. --- Hello, my name is Mrs Okafor and I am 40 years old. I teach English. ---
Illustration:
for person in people:
person.introduce()
|
V
Student.introduce() -> "I am in JSS3"
Teacher.introduce() -> "I teach Maths"
Mini summary: Inheritance shares code. Polymorphism lets each object respond in its own way.
Definition: Encapsulation protects sensitive data like scores and salary.
Why it is important: It prevents accidental changes and errors.
Simple explanation: Scores are private. You can only add them through the add_score method. Salary is private. You can only change it through the salary setter.
Real-life example: A bank protects your balance.
School example: A school protects student records.
Home example: A family protects private documents.
Nigerian example: A bank protects your account details.
Example code:
ada = Student("Ada", 14, "JSS3")
ada.add_score(85)
ada.add_score(90)
ada.add_score(78)
# ada.__scores = [100, 100, 100] # ERROR! Cannot access directly
print("Ada's average: " + str(ada.get_average()))
Output:
Ada's average: 84.33333333333333
Illustration:
Private: __scores
Public: add_score(), get_average()
|
V
Scores are safe!
Mini summary: Encapsulation protects sensitive data. Use private attributes and safe methods.
Definition: Abstraction hides complicated details and shows only what is needed.
Why it is important: It makes your program easier to use.
Simple explanation: Users of your program do not need to know how scores are stored. They just call add_score and get_average.
Real-life example: When you drive a car, you do not need to know how the engine works.
School example: When you check your timetable, you do not need to know how it was made.
Home example: When you use a remote, you do not need to know how the TV works.
Nigerian example: When you use an ATM, you do not need to know how the bankβs computers work.
Example code:
# The user does not need to know how scores are stored.
# They just use add_score and get_average.
ada = Student("Ada", 14, "JSS3")
ada.add_score(85)
ada.add_score(90)
print("Average: " + str(ada.get_average()))
Illustration:
User sees: add_score() get_average() User does not see: __scores list how average is calculated
Mini summary: Abstraction hides complexity. Users see only what they need.
Definition: You will now write the complete program.
Why it is important: This is the goal of the module.
Simple explanation: Put all the classes together. Create objects. Use methods. Print results.
Real-life example: A complete school management system.
School example: A program to manage students, teachers, and courses.
Home example: A program to manage family members and chores.
Nigerian example: A program to manage a Nigerian school.
Example code:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def introduce(self):
print("Hello, my name is " + self.name + " and I am " + str(self.age) + " years old.")
class Student(Person):
def __init__(self, name, age, class_level):
super().__init__(name, age)
self.class_level = class_level
self.__scores = []
def add_score(self, score):
if 0 <= score <= 100:
self.__scores.append(score)
else:
print("Error: Score must be between 0 and 100.")
def get_average(self):
if len(self.__scores) == 0:
return 0
return sum(self.__scores) / len(self.__scores)
def study(self):
print(self.name + " is studying.")
def introduce(self):
super().introduce()
print("I am in " + self.class_level + ".")
class Teacher(Person):
def __init__(self, name, age, subject, salary):
super().__init__(name, age)
self.subject = subject
self.__salary = salary
@property
def salary(self):
return self.__salary
@salary.setter
def salary(self, amount):
if amount > 0:
self.__salary = amount
else:
print("Error: Salary must be positive.")
def teach(self):
print(self.name + " is teaching " + self.subject + ".")
def introduce(self):
super().introduce()
print("I teach " + self.subject + ".")
class Course:
def __init__(self, name, teacher):
self.name = name
self.teacher = teacher
self.students = []
def add_student(self, student):
self.students.append(student)
print(student.name + " has been added to " + self.name + ".")
def show_details(self):
print("Course: " + self.name)
print("Teacher: " + self.teacher.name)
print("Students: " + str(len(self.students)))
# Create teachers
mr_bello = Teacher("Mr Bello", 35, "Maths", 150000)
mrs_okafor = Teacher("Mrs Okafor", 40, "English", 180000)
# Create students
ada = Student("Ada", 14, "JSS3")
tunde = Student("Tunde", 15, "JSS2")
ngozi = Student("Ngozi", 13, "JSS1")
# Add scores
ada.add_score(85)
ada.add_score(90)
ada.add_score(78)
tunde.add_score(70)
tunde.add_score(65)
ngozi.add_score(95)
ngozi.add_score(88)
# Create courses
maths = Course("Mathematics", mr_bello)
english = Course("English", mrs_okafor)
# Add students to courses
maths.add_student(ada)
maths.add_student(tunde)
english.add_student(ada)
english.add_student(ngozi)
# Show all people
print("=== PEOPLE ===")
people = [ada, tunde, ngozi, mr_bello, mrs_okafor]
for person in people:
person.introduce()
print("---")
# Show course details
print("=== COURSES ===")
maths.show_details()
english.show_details()
# Show averages
print("=== AVERAGES ===")
print("Ada: " + str(ada.get_average()))
print("Tunde: " + str(tunde.get_average()))
print("Ngozi: " + str(ngozi.get_average()))
Output:
Ada has been added to Mathematics. Tunde has been added to Mathematics. Ada has been added to English. Ngozi has been added to English. === PEOPLE === Hello, my name is Ada and I am 14 years old. I am in JSS3. --- Hello, my name is Tunde and I am 15 years old. I am in JSS2. --- Hello, my name is Ngozi and I am 13 years old. I am in JSS1. --- Hello, my name is Mr Bello and I am 35 years old. I teach Maths. --- Hello, my name is Mrs Okafor and I am 40 years old. I teach English. --- === COURSES === Course: Mathematics Teacher: Mr Bello Students: 2 Course: English Teacher: Mrs Okafor Students: 2 === AVERAGES === Ada: 84.33333333333333 Tunde: 67.5 Ngozi: 91.5
Illustration:
Person (parent)
|
V
+-------------+ +-------------+
| Student | | Teacher |
| __scores | | __salary |
| add_score() | | teach() |
| get_average()| | introduce() |
+-------------+ +-------------+
| |
V V
Course connects students and teachers
Mini summary: You built a complete school management system using all four pillars of OOP.
Definition: Testing means running your program and checking for errors.
Why it is important: You want your program to work correctly.
Simple explanation: Run the program. Check the output. Try different inputs. Fix any problems.
Real-life example: Before a car is sold, it is tested on the road.
School example: Before an exam, you practise with past questions.
Home example: Before serving food, you taste it.
Nigerian example: Before a wedding, the family does a rehearsal.
Checklist:
Illustration:
Run Program
|
V
Check Output
|
V
Find Errors
|
V
Fix Errors
|
V
Run Again
|
V
Works! π
Mini summary: Always test your program. Check all parts. Fix any problems.
Definition: Improving means making your program better.
Why it is important: Good programs can always be better.
Simple explanation: You can add more features. You can fix bugs. You can make the code cleaner.
Real-life example: A phone gets updates to add new features.
School example: A student improves their essay after getting feedback.
Home example: You improve a recipe after tasting it.
Nigerian example: A tailor improves a dress after the first fitting.
Ideas for improvement:
Illustration:
Basic Program
|
V
Add Features
|
V
Fix Bugs
|
V
Better Program!
Mini summary: You can always improve your program. Add features. Fix bugs. Make it better.
Definition: OOP is used in almost all modern software.
Why it is important: Knowing this helps you understand why you are learning OOP.
Simple explanation: Video games, banking apps, social media, and websites all use OOP.
Real-life example: In a game, each character is an object with health, speed, and actions.
School example: A school management system uses objects for students, teachers, and courses.
Home example: A smart home app uses objects for lights, fans, and doors.
Nigerian example: A bank app uses objects for customers, accounts, and transactions.
Illustration:
Real Software
|
V
+--------+ +--------+ +--------+
| Game | | Bank | | Social |
| objects| | objects| | objects|
+--------+ +--------+ +--------+
All use OOP!
Mini summary: OOP is used in games, banking, social media, and many other programs.
Definition: These are mistakes beginners make when building big programs.
Why it is important: Knowing them helps you avoid them.
Simple explanation: Here are some mistakes to watch out for.
List of mistakes:
Illustration:
Bad Program Good Program +----------------+ +----------------+ | One big class | | Many small | | No plan | | classes | | No tests | | Plan first | +----------------+ +----------------+
Mini summary: Avoid common mistakes. Plan first. Use small classes. Test everything.
Definition: You have built a complete OOP program.
Why it is important: Reviewing helps you remember.
Simple explanation: You used classes, objects, inheritance, polymorphism, encapsulation, and abstraction.
Real-life example: Like finishing a big project.
School example: Like finishing your final year project.
Home example: Like building a piece of furniture.
Nigerian example: Like completing a big tailoring job.
Illustration:
Learn OOP
|
V
Learn Classes & Objects
|
V
Learn Inheritance & Polymorphism
|
V
Learn Encapsulation & Abstraction
|
V
Build Complete Program
|
V
Celebrate π
Mini summary: You built a complete OOP program. You are now an OOP programmer!
| Word | Simple Definition |
|---|---|
| Encapsulation | Keeping data safe inside an object. |
| Abstraction | Hiding complicated details. |
| Inheritance | When one class gets data and methods from another. |
| Polymorphism | βMany formsβ β different objects respond to the same action differently. |
| Parent class | The class being inherited from. |
| Child class | The class that inherits. |
| Override | Changing a method in the child class. |
| super() | A function that calls the parentβs method. |
| Private attribute | Data that only the class can access. |
| Getter | A method that returns private data. |
| Setter | A method that changes private data safely. |
| Property | A special way to use getters and setters in Python. |
| Abstract class | A class that cannot be used directly. |
| Test | Running a program to check for errors. |
Plan the Program
|
V
Create Parent Class
|
V
Create Child Classes
|
V
Add Encapsulation
|
V
Add Polymorphism
|
V
Create Objects
|
V
Test
|
V
Improve
|
V
Celebrate π
Module 1: What is OOP? Module 2: Classes and Objects Module 3: Inheritance and Polymorphism Module 4: Encapsulation and Abstraction Module 5: Complete Program Now: You are an OOP programmer!
| Pillar | Where Used | Example |
|---|---|---|
| Encapsulation | Student.__scores, Teacher.__salary | Private data |
| Abstraction | add_score(), get_average() | Hidden complexity |
| Inheritance | Student(Person), Teacher(Person) | Shared code |
| Polymorphism | introduce() in Student and Teacher | Different results |
| Feature | Without OOP | With OOP |
|---|---|---|
| Organisation | Messy | Clean |
| Reuse | Hard | Easy |
| Fixing bugs | Hard | Easier |
| Adding features | Hard | Easier |
| Working in teams | Hard | Easier |
Lesson 1: The four pillars of OOP are encapsulation, abstraction, inheritance, and polymorphism.
Lesson 2: Plan your program before you code.
Lesson 3: The Person class holds common data for all people.
Lesson 4: The Student class inherits from Person and adds scores.
Lesson 5: The Teacher class inherits from Person and adds subject and salary.
Lesson 6: The Course class connects students and teachers.
Lesson 7: Inheritance shares code. Polymorphism lets objects respond differently.
Lesson 8: Encapsulation protects sensitive data.
Lesson 9: Abstraction hides complexity.
Lesson 10: You built a complete school management system.
Lesson 11: Always test your program.
Lesson 12: Improve your program over time.
Lesson 13: OOP is used in real software.
Lesson 14: Avoid common mistakes in large programs.
Lesson 15: You built a complete OOP program. You are an OOP programmer!
In this module, you put everything together. You reviewed the four pillars of OOP: encapsulation, abstraction, inheritance, and polymorphism. You planned a complete program. You created a parent class called Person. You created child classes called Student and Teacher. You created a Course class. You used inheritance to share code. You used polymorphism to let objects introduce themselves differently. You used encapsulation to protect scores and salary. You used abstraction to hide complexity. You built a complete school management system. You tested it and learned how to improve it. You also learned how OOP is used in real software. You are now a complete OOP programmer!
Match the word to its meaning.
| Word | Meaning |
|---|---|
| 1. Encapsulation | A. When one class gets data from another |
| 2. Abstraction | B. Protecting data |
| 3. Inheritance | C. Different objects respond differently |
| 4. Polymorphism | D. Hiding complexity |
| 5. Testing | E. Checking for errors |
Answers: 1-B, 2-D, 3-A, 4-C, 5-E
Title: Build a Complete Program Together
Instructions: In groups of 3, choose a topic (e.g., hospital, market, transport). Plan the classes. Create a parent class and child classes. Use encapsulation and polymorphism. Write the code together. Test it. Present to the class.
Title: My First Complete OOP Program
Instructions: Write a program with a parent class called Shape and child classes Circle, Square, and Triangle. Use abstraction with an abstract area() method. Use polymorphism to call area() on all shapes. Write down what happens.
Title: A Complete OOP Project
Instructions: Build a program for a small business (e.g., a shop, a restaurant, a library). Use all four pillars of OOP:
Task: Write a short paragraph (5 sentences) explaining what you learned in this module. Then, list three things you found easy and one thing you found hard. Finally, describe your complete program and how it uses the four pillars of OOP.
Congratulations! You have completed all five modules of the Object Oriented Programming course. In the next steps, you can:
You are now an OOP programmer. Go and build amazing things! π
End of Module Five Β· Object Oriented Programming