Study Guide

Object-oriented programming concepts

CIE A-Level Computer ScienceΒ· 25 min read

1. Classes and Objectsβ˜…β˜…β˜†β˜†β˜†β± 10 min

πŸ“˜ Definition

Class

A reusable blueprint or template that defines the common attributes (data) and methods (behaviours) that all objects of that type will share.

Example:

A Car class defines that all cars have a colour, model, and can accelerate.

An object is an instance of a class. Each object has its own unique values for the attributes defined by the class, but shares the same methods as all other objects of that class. This allows multiple distinct entities to be created from a single template.

πŸ“ Worked Example

Model a simple bank account system using a class and two object instances. List the attributes and methods required.

  1. 1

    First, define the BankAccount class as the blueprint, with common attributes and methods:

  2. 2

    Attributes: account holder name, current balance; Methods: deposit funds, withdraw funds, check balance

  3. 3

    Next, create two distinct object instances from the BankAccount class, with unique attribute values:

  4. 4
    1. aliceAccount = BankAccount("Alice Smith", 1500) 2. bobAccount = BankAccount("Bob Jones", 3250)
  5. 5

    Both objects use the same deposit() and withdraw() methods defined in the class, but operate on their own independent balance values.

2. Encapsulation and Abstractionβ˜…β˜…β˜†β˜†β˜†β± 12 min

πŸ“˜ Definition

Encapsulation

The principle of bundling attributes and methods within a class, and restricting direct access to internal data to prevent unintended modification.

Example:

A bank account's balance cannot be changed directly, only via validated deposit/withdraw methods.

Abstraction is closely related to encapsulation: it means hiding unnecessary implementation details from the user, only exposing the essential features of an object. This reduces complexity and allows users to interact with objects without understanding how they work internally.

πŸ“ Worked Example

Explain how encapsulation works in a Student class that stores student exam grades.

  1. 1

    The Student class bundles the grades attribute (a list of marks) and methods to add a grade and calculate the average grade.

  2. 2

    The grades attribute is marked as private, meaning it cannot be accessed or modified directly from outside the class.

  3. 3

    All changes to grades must go through the addGrade() method, which validates that the new grade is between 0 and 100 before adding it, preventing invalid data.

  4. 4

    Users only interact with addGrade() and getAverage(), so the internal implementation of how grades are stored is abstracted away.

3. Inheritanceβ˜…β˜…β˜…β˜†β˜†β± 12 min

πŸ“˜ Definition

Inheritance

A mechanism where a new (child/sub) class derives attributes and methods from an existing (parent/super) class, enabling code reuse and hierarchical classification.

Inheritance allows child classes to override inherited methods to provide specialised behaviour, while still retaining all features of the parent class. This supports hierarchical modelling of related concepts, avoiding redundant code.

πŸ“ Worked Example

Use inheritance to model different types of vehicles for a municipal parking system.

  1. 1

    First create a parent superclass Vehicle that defines common attributes and methods all vehicles share:

  2. 2

    Attributes: registration number, manufacturer, model; Method: getRegistrationNumber()

  3. 3

    Create two child subclasses Car and Motorcycle that inherit all members from Vehicle:

  4. 4

    Car adds numberOfDoors attribute and isElectric() method; Motorcycle adds engineCapacity attribute and hasSideCar() method

  5. 5

    Both child classes automatically inherit the registrationNumber attribute and getRegistrationNumber() method, so this code does not need to be rewritten for each subclass.

4. Polymorphismβ˜…β˜…β˜…β˜†β˜†β± 13 min

πŸ“˜ Definition

Polymorphism

The ability of objects from different subclasses to respond to the same method name with different, class-specific behaviour.

The most common form of polymorphism in OOP is method overriding, where a child class provides a specific implementation of a method that is already defined in the parent class. This allows code to interact with any parent class object without needing to know which specific subclass it belongs to.

πŸ“ Worked Example

Demonstrate polymorphism using the vehicle parking example, where all vehicles need to calculate their parking fee.

  1. 1

    Define a method calculateParkingFee(hours) in the parent Vehicle class with a default rate of $2 per hour.

  2. 2

    Override the method in the Car subclass: cars have a minimum fee of $5, so the method returns max(5, 2 * hours).

  3. 3

    Override the method in the Motorcycle subclass: motorcycles have a flat rate of $1.50 per hour, so the method returns 1.5 * hours.

  4. 4

    When looping through a list of Vehicle objects to calculate total fees, the correct version of calculateParkingFee() is called automatically for each object, regardless of its subclass.

Exam tip:

When asked to explain polymorphism in exams, always include an example of method overriding to earn full marks.

5. Common Pitfalls

Wrong move:

Confusing classes and objects, calling a class an instance of an object

Why:

The relationship is reversed: classes are templates, objects are instances created from the template

Correct move:

Always state that an object is an instance of a class, which acts as the template for the object

Wrong move:

Mixing up encapsulation and abstraction, defining encapsulation as hiding implementation details

Why:

The core focus of each concept is different, and examiners mark down for mixing the definitions

Correct move:

Remember: encapsulation = data bundling + access restriction; abstraction = hiding unnecessary implementation complexity

Wrong move:

Stating that inheritance flows from child class to parent class

Why:

Inheritance creates new classes from existing classes, so the direction is reversed in this claim

Correct move:

Child (sub) classes inherit attributes and methods from existing parent (super) classes

Wrong move:

Only defining polymorphism as 'many shapes' with no practical example

Why:

Examiners expect an explanation of how polymorphism works in OOP, not just a translation of the term

Correct move:

Explain polymorphism as the ability of different subclass objects to respond to the same method name with different behaviour, usually via method overriding

6. Quick Reference Cheatsheet

OOP Concept

Core Definition

Main Purpose

Class

Blueprint/template for objects

Define shared attributes and methods

Object

Instance of a class

Represent individual entities

Encapsulation

Bundle data + restrict access

Prevent invalid modification of internal data

Abstraction

Hide implementation details

Reduce complexity for end users

Inheritance

Child inherits from parent

Enable code reuse and hierarchical modelling

Polymorphism

Same method name, different behaviour

Allow generic code for multiple subclasses

When this came up on past exams

AI-estimated based on syllabus patterns β€” cross-check with official past papers for accuracy. Use only as revision-focus signals.

  • 2022 Β· 12

    Explain OOP encapsulation principle

  • 2023 Β· 13

    Compare inheritance vs polymorphism

  • 2024 Β· 11

    Model system with OOP inheritance

What's Next

Now that you understand the core concepts of OOP, you can move on to implementing these concepts in code, which is tested in both Paper 1 and Paper 2 of CIE 9618. OOP is the foundation for most modern software development, so mastering these core concepts will help you model complex problems efficiently, answer theory questions correctly, and write structured, maintainable code for your programming projects. Building a solid foundation here also prepares you for further computer science study at university.