Object-oriented programming (OOP) is a paradigm that models a program as a collection of interacting objects — each bundling its own data (attributes) and behaviour (methods) into a self-contained unit. Rather than writing a sequence of instructions, you design blueprints called classes and then create instances of them.
What is the blueprint-and-house analogy?
The easiest way to grasp OOP is through an architectural metaphor. A class is like a blueprint for a house: it specifies that every house will have a number of rooms, a front door colour, and an address, and that every house can perform actions like "open the door" or "turn on the lights". A class defines the type but is not itself a thing you can live in.
An object is an actual house built from that blueprint. Every house built from the same blueprint is an instance of that class. Instance A might be at 14 Maple Street with a red door; instance B might be at 7 Oak Avenue with a blue door. Same blueprint — different data.
What are attributes and methods?
| Concept | Definition | Example |
|---|---|---|
| Attribute | A variable stored inside an object — its data | name, age, balance |
| Method | A subroutine defined inside a class — its behaviour | greet(), deposit(), calculate_grade() |
| Class | The blueprint defining attributes and methods | Student, BankAccount, Vehicle |
| Object | A specific instance of a class with actual data values | student1 = Student("Ali", 15) |
Pseudocode class definition:
CLASS Student
PRIVATE name
PRIVATE age
PUBLIC PROCEDURE new(studentName, studentAge)
name = studentName
age = studentAge
ENDPROCEDURE
PUBLIC FUNCTION getName()
RETURN name
ENDFUNCTION
PUBLIC PROCEDURE birthday()
age = age + 1
ENDPROCEDURE
ENDCLASS
Creating and using objects:
s1 = new Student("Aisha", 14)
s2 = new Student("Ben", 15)
OUTPUT s1.getName() → "Aisha"
s1.birthday()
OUTPUT s1.age → 15 (Aisha is now 15)
OUTPUT s2.age → 15 (Ben unchanged)
Each object has its own copy of name and age — they do not interfere with each other.
What is encapsulation?
Encapsulation is the OOP principle of keeping an object's internal data private — accessible only through the object's own public methods. Think of a cash machine: you interact with it via buttons (public methods — withdraw, check balance). You cannot reach inside and directly change the balance variable. The internal state is hidden.
Why it matters:
| Without encapsulation | With encapsulation |
|---|---|
Any part of the program can change balance directly |
Only deposit() and withdraw() can change balance |
| Bugs can come from anywhere | Bugs in balance must be inside the class |
| Validation logic can be bypassed | Validation is enforced by the method |
In pseudocode and Python, private attributes are marked with a naming convention (PRIVATE keyword, or __ prefix in Python) to signal that external code should not access them directly.
What is inheritance?
Inheritance allows one class (the child or subclass) to inherit all the attributes and methods of another class (the parent or superclass), and then add its own specialisations. It models an is-a relationship.
Example — an Animal parent class with Dog and Cat children:
CLASS Animal
PRIVATE name
PRIVATE sound
PUBLIC PROCEDURE new(animalName, animalSound)
name = animalName
sound = animalSound
ENDPROCEDURE
PUBLIC PROCEDURE makeSound()
OUTPUT name + " says " + sound
ENDPROCEDURE
ENDCLASS
CLASS Dog INHERITS Animal
PUBLIC PROCEDURE fetch()
OUTPUT name + " fetches the ball!"
ENDPROCEDURE
ENDCLASS
A Dog object inherits makeSound() from Animal and gains the additional fetch() method. Cat could inherit the same and add purr() instead.
Benefits of inheritance:
- Code reuse — shared behaviour written once in the parent
- Extensibility — add specialised behaviour in child classes without modifying the parent
- Hierarchy — models real-world relationships (every
Dogis anAnimal)
What are the four main OOP principles at GCSE?
| Principle | Meaning |
|---|---|
| Encapsulation | Bundle data and methods; keep data private |
| Inheritance | Child class inherits parent's attributes and methods |
| Abstraction | Hide internal complexity; expose only what is needed |
| Polymorphism | Different classes can implement the same method name differently (less detail required at GCSE) |
Frequently asked questions
What is the difference between a class and an object?
A class is a template or blueprint — it exists in code but has no data values yet. An object is a concrete instance created from that class, with actual values stored in its attributes. The Student class defines what a student looks like; s1 = new Student("Aisha", 14) creates a real student object with the name "Aisha" and age 14.
What does a constructor do?
A constructor is a special method (often called __init__ in Python or new in pseudocode) that runs automatically when an object is created. Its job is to initialise the object's attributes with starting values. Without a constructor, the object would be created with no data in its attributes, which usually causes errors when other methods try to use them.
How does OOP differ from procedural programming?
Procedural programming organises code as a sequence of subroutines that operate on data passed between them — data and behaviour are separate. OOP bundles data and behaviour together in objects. OOP tends to model complex, long-lived systems (apps, games, operating systems) better because each object manages its own state. Procedural code is often simpler for short scripts and sequential tasks.
Does Python support OOP?
Yes. Python fully supports OOP with the class keyword, __init__ constructors, self references, and single/multiple inheritance. It is the language most GCSE courses use to demonstrate OOP concepts. class Dog(Animal): declares Dog as a subclass of Animal; super().__init__(...) calls the parent constructor from the child.
Explore object-oriented thinking with Professor Turing's guided analogies and coding challenges at aitutors.me.