What is Object-Oriented Programming?

Before OOP, programs were written in a procedural style — a list of instructions operating on separate variables. OOP changes this by bundling related data and behaviour together into objects.

Procedural vs Object-Oriented

In procedural code you track a car like this:

car_brand  = "Toyota"
car_speed  = 0
car_colour = "red"
# Three unrelated variables for one car

With OOP you create a Car class and each car is one object:

class Car:
    def __init__(self, brand, colour):
        self.brand  = brand
        self.colour = colour
        self.speed  = 0

my_car = Car("Toyota", "red")
All data lives inside my_car

The Four Pillars of OOP

  • Encapsulation — bundle data and methods; hide internal details
  • Inheritance — a child class reuses code from a parent class
  • Polymorphism — the same method name behaves differently in different classes
  • Abstraction — expose only what is necessary; hide complexity

Advantages of OOP

  • Modularity — each class is a self-contained unit
  • Reusability — write a class once, use it everywhere
  • Maintainability — changes to one class rarely break others
  • Collaboration — teams can work on separate classes simultaneously

Disadvantages of OOP

  • Steeper learning curve for beginners
  • More complex than needed for very small programs
  • Deep inheritance hierarchies can become hard to follow

Your Task

Read and run the procedural example first. Then complete the object-oriented version: create one Car object, accelerate it, and print its data using the object instead of separate variables.

Print: OOP Car: Toyota, red, 30 km/h

Section 1/5Procedural vs Object-Oriented

Procedural vs Object-Oriented

In procedural code you track a car like this:

What is Object-Oriented Programming?

Before OOP, programs were written in a procedural style — a list of instructions operating on separate variables. OOP changes this by bundling related data and behaviour together into objects.

Procedural vs Object-Oriented

In procedural code you track a car like this:

car_brand  = "Toyota"
car_speed  = 0
car_colour = "red"
# Three unrelated variables for one car

With OOP you create a Car class and each car is one object:

class Car:
    def __init__(self, brand, colour):
        self.brand  = brand
        self.colour = colour
        self.speed  = 0

my_car = Car("Toyota", "red")
All data lives inside my_car

Output:

Click "Check" to run your code.