Object-Oriented Programming (OOP)

Updated Nov 30, 2025

Object-Oriented Programming (OOP)

Object-Oriented Programming (OOP) is a way of writing code where we think in terms of real things.

  • We create a class → a plan (what something HAS and what it CAN DO)
  • We create objects → the real things made from that plan

OOP helps us:

  • Keep information (attributes) and actions (methods) together
  • Write code that is clean, organized, and easy to reuse

We will use a car example to understand OOP, because almost everyone has seen a car and knows what it can do.

alt OOP car example

How OOP Fits with Class and Object

From the Class and Object notes:

  • Class → Plan (like Car with color, model, company, start, stop, honk)
  • Object → Real car made from that plan
  • car1 = Car("Red", "Cooper", "MINI")
  • car2 = Car("Yellow", "City", "Honda")

Each car:

  • HAS its own attributes → color, model, company
  • CAN DO methods → start, stop, honk

OOP is about using many such classes and objects to build your full program.

Four Pillars of OOP (Using Car Examples)

OOP has four main ideas, often called the four pillars:

  • Encapsulation : Keep data and methods together in one class
  • Inheritance : Make a new class from an old class and reuse code
  • Polymorphism : Same method name, different behaviour for different objects
  • Abstraction : Show simple methods, hide complex details