SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
CAIE 9618 · Paper 4 · Topic 4.1.2

OOP
Fundamentals

Classes · Objects · Attributes · Methods · Encapsulation · Constructors · CAIE Pseudocode

CSZone Cambridge International AS & A Level Computer Science 9618
Classes & Objects

Blueprint vs Instance

Object-Oriented Programming models the world as interacting objects. A class is the blueprint — it defines attributes (data) and methods (behaviour). An object is a specific instance of that class created at runtime.
// CAIE 9618 Pseudocode CLASS syntax
CLASS BankAccount
PRIVATE Balance : REAL
PRIVATE AccountNumber : STRING

PUBLIC PROCEDURE NEW(AccNo:STRING, InitBal:REAL)
AccountNumber ← AccNo
Balance ← InitBal
ENDPROCEDURE

PUBLIC FUNCTION GetBalance() : REAL
RETURN Balance
ENDFUNCTION

PUBLIC PROCEDURE Deposit(Amount : REAL)
Balance ← Balance + Amount
ENDPROCEDURE
ENDCLASS

// Instantiate an object
DECLARE MyAcc : BankAccount
MyAcc ← NEW BankAccount("ACC001", 500.00)
MyAcc.Deposit(200.00)
CLASS vs OBJECT
Class — defines the structure; no memory allocated for attributes yet; exists at compile time
Object — a specific instance; memory allocated for its attributes; exists at run time
Many objects can be created from one class: MyAcc, YourAcc, JointAcc — all BankAccount objects with different data
CONSTRUCTOR (NEW)
Special method called when an object is created
In CAIE pseudocode: PUBLIC PROCEDURE NEW(params)
Initialises the object's attributes to valid starting values
Called with Obj ← NEW ClassName(args)
Encapsulation

Protecting Data — Public vs Private

Encapsulation bundles data (attributes) and methods together inside a class, and controls access using access modifiers. It hides internal implementation details from the outside world — only the public interface is exposed.
PRIVATE
Accessible only within the class itself
Attributes should almost always be PRIVATE
Prevents external code from putting the object into an invalid state (e.g. negative balance)
PUBLIC
Accessible from outside the class
Methods (procedures/functions) that form the class's interface should be PUBLIC
Constructor (NEW) is always PUBLIC
GETTERS & SETTERS
Because attributes are private, public accessor methods are needed to read/modify them safely:
PUBLIC FUNCTION GetBalance() : REAL
RETURN Balance // getter
ENDFUNCTION

PUBLIC PROCEDURE SetBalance(b : REAL)
IF b >= 0 THEN
Balance ← b // validated setter
ENDIF
ENDPROCEDURE
WHY ENCAPSULATION?
Validation can be enforced inside the setter. Internal implementation can change without breaking external code. Reduces coupling between classes → easier maintenance.
The Four Pillars of OOP

Core Concepts Overview

1. Encapsulation
Bundling data and methods together; restricting access with PRIVATE/PUBLIC modifiers; hiding implementation details behind a public interface.
2. Inheritance
A subclass (derived class) inherits all public attributes and methods of a superclass (base class). Promotes code reuse. Subclass can add new members or override inherited methods. (Covered in 4.1.3)
3. Polymorphism
Same method name, different behaviour depending on the object. A superclass reference can call overridden methods in different subclasses at runtime. (Covered in 4.1.3)
4. Abstraction
Hiding complex implementation details and exposing only the essential interface the user needs. The user of a class doesn't need to know HOW it works — only what it does.
Exam Practice

Cambridge-style questions

Question 1
A class Student is defined with a private attribute Score and a public method SetScore(s : INTEGER). Explain why Score is declared as private and describe the benefit of providing a public method to change it. [3]
1
Score is declared PRIVATE so that it can only be accessed and modified from within the Student class itself — external code cannot directly change it, preventing invalid values being set.
1
By providing a public SetScore method, the class can include validation logic — for example, rejecting negative scores or values over 100 — before allowing the change. This keeps the object in a valid state (data integrity / encapsulation).
1
The internal implementation of how Score is stored can be changed without affecting any external code that uses the class — only the public interface (method signatures) needs to remain stable.
Common Mistakes

Don't lose easy marks

1
Saying "a class IS an object" — a class is the blueprint/template; an object is an instance of the class. The class defines structure; the object is created in memory at runtime with actual data values.
2
Making attributes PUBLIC in exam answers — unless specifically told otherwise, CAIE expects attributes to be PRIVATE (encapsulation). Declaring attributes as public loses the encapsulation mark and potentially further marks for related explanations.
3
Confusing a constructor with a regular method — the constructor (NEW in CAIE pseudocode) is called automatically when an object is created and initialises attributes. It is NOT called manually like a regular method — Obj ← NEW ClassName() is the instantiation syntax.
Topic Summary — 4.1.2

What You Need to Know

CLASS & OBJECT
Class = blueprint (attributes + methods). Object = instance with real data. Constructor NEW initialises attributes. Multiple objects from one class.
ENCAPSULATION
PRIVATE attributes, PUBLIC methods. Getters/setters with validation. Hides implementation. Reduces coupling. Enables safe modification.
4 PILLARS
Encapsulation (hide data), Inheritance (reuse), Polymorphism (same name different behaviour), Abstraction (hide complexity). Know definitions for each — they come up in Paper 4 questions.
CSZone

Next Video

4.1.3
OOP Inheritance & Polymorphism
Subclass · Override · Abstract Class · Interfaces
Head to CSZone.co.uk for the complete worksheet, quiz, and interactive tools