What is Object-Oriented Programming?

15 mintext

Theory & Concepts

Why OOP Matters

Object-Oriented Programming (OOP) lets us organise code around the things we talk about-orders, learners, dashboards-making large codebases easier to reason about.

Pillars to Remember

  • Encapsulation groups data with the code that uses it.
  • Inheritance lets specialised objects reuse behaviour from base classes.
  • Polymorphism allows different objects to respond to the same message.
  • Abstraction hides messy implementation details behind clear public APIs.

When to Reach for OOP

Anytime you need to model entities with state and behaviour that evolve over time.

Lesson Content

Understand how OOP models real-world systems with objects that bundle data and behavior.

Code Example

python
class Course:
"""Represent a course with a title and total lessons."""
def __init__(self, title: str, lessons: int):
self.title = title
self.lessons = lessons
self.completed = 0
def complete_lesson(self) -> None:
if self.completed < self.lessons:
self.completed += 1
def progress(self) -> float:
return self.completed / self.lessons * 100
python_basics = Course("Python Basics", 20)
python_basics.complete_lesson()
print(python_basics.title, f"{python_basics.progress():.0f}% complete")
Section 1 of 14 • Lesson 1 of 8