Welcome
Object-Oriented Programming, Learned by Doing
Object-Oriented Programming becomes easier when we learn by doing. Complete the activities below to explore classes, objects, attributes, methods, and the four main principles of OOP.
Section 1
What Is OOP?
Object-Oriented Programming (OOP) is a programming paradigm that organizes software around objects, which combine data (attributes) and behavior (methods).
Objects Represent Real-World Entities
Class → Objects
Student
Class = Blueprint · Object = Instance created from the blueprint
Activity 1: Class or Object?
Not startedDecide whether each item represents a class or an object.
Instructor note: Ask students out loud before revealing the buttons’ result. Pause 3–5 seconds before clicking.
Vote, Argue, Vote Again
Predict: What Does taxi Show?
Read the code, then vote for what you think it prints. We will show the room’s results live. Argue your answer with a neighbor, then vote again before we reveal the answer.
class Car:
def __init__(self):
self.speed = 0
def accelerate(self):
self.speed += 10
my_car = Car()
taxi = Car()
my_car.accelerate()
my_car.accelerate()
print(taxi.speed)
Vote recorded. Watching the room’s results live…
Answer: 0. taxi is a separate object from my_car. Each object keeps its own independent copy of speed — calling accelerate() on my_car never touches taxi.
Section 2
Attribute or Method?
Attributes describe what an object HAS.
Methods describe what an object CAN DO.
Example: Student Object
Attributes
- name
- studentID
- GPA
- major
Methods
- study()
- registerCourse()
- submitAssignment()
- viewGrade()
Activity 2: Attribute or Method?
Not startedClick each item below and classify it as an Attribute or a Method.
Instructor note: This works well as a rapid-fire class activity. Ask for a show of hands before each click.
Section 3
Activity 3: Build Your Own Class
Not startedChoose a class, then select the attributes and methods that belong to it.
Instructor note: Have the class vote on which category to build. Ask why each distractor is wrong before checking.
Select every attribute and method that belongs to this class:
Section 4
Activity 4: From Class to Object
Not startedA class is the blueprint. Now let’s create an object.
Instructor note: Fill the form live with a volunteer’s own name and major to make it personal.
Each object below is an instance of the Student class: same blueprint, different data.
Both objects belong to the same Student class, but each one holds its own data.
Section 5
Activity 5: Fix the Python Code
Not startedRead the code below. Something is broken.
class Student:
def __init__(self, name, major):
self.name = name
self.major = major
def study(self):
print(name + " is studying")
student1 = Student("Sara", "Cybersecurity")
student1.study()
What is wrong with the code?
Corrected code:
def study(self):
print(self.name + " is studying")
Instructor note: Ask “What does self refer to?” before revealing option B is correct.
Section 6
The Four Pillars of OOP
Encapsulation
Encapsulation bundles data and methods together and controls access to an object’s internal state.
Example: A Bank Account’s balance should not be changed directly. Use deposit() and withdraw() instead.
Simple idea: Protect and control data.
Abstraction
Abstraction hides unnecessary implementation details and shows only what the user needs.
Example: A driver uses car.start() without needing to understand the engine system.
Simple idea: Hide complexity.
Inheritance
Inheritance allows one class to reuse and extend the attributes and methods of another class.
Example: Employee → Professor. A Professor is an Employee.
class Employee:
...
class Professor(Employee):
...
Simple idea: Reuse and extend.
Polymorphism
Polymorphism allows the same method or interface to behave differently depending on the object.
Example: Professor.work(), Engineer.work(), and Doctor.work() all use work() but produce different behavior.
Simple idea: Same interface, different behavior.
Activity 6: Which OOP Principle Is This?
Not startedRead each scenario and choose the OOP principle it demonstrates.
Cybersecurity Case Study
Design a Security Incident Class
We can also apply OOP to cybersecurity systems. Below is a class used inside a Security Operations Center (SOC) to track incidents.
Possible Attributes
- incidentID
- severity
- status
- detectionTime
- assignedAnalyst
Possible Methods
- assignAnalyst()
- escalate()
- closeIncident()
- generateReport()
Classify each item below as an Attribute or a Method:
The Completed Class
class SecurityIncident:
def __init__(self, incident_id, severity, status):
self.incident_id = incident_id
self.severity = severity
self.status = status
def escalate(self):
print("Incident escalated")
incident1 = SecurityIncident("INC-001", "High", "Open")
Live SOC Dashboard
Instructor note: Frame this as “incident1 is an object of the SecurityIncident class. Watch what happens when we call a method on it.”
Final Assessment
The 5-Minute Class Challenge
Five questions covering everything from this lab: classes, objects, attributes, methods, and the four pillars. Enter your name, race the clock, and climb the leaderboard.
Ready to compete, ?
You will have 5 minutes to answer all 5 questions.
Result
Top 10 Leaderboard
0 entriesRanked by score, then by fastest time.
| Rank | Name | Class | Score | Time |
|---|
No one has taken the challenge yet. Be the first!