Object-Oriented Programming (OOP) is a programming paradigm that organises code around objects — entities that combine data (attributes) and behaviour (methods). OOP models real-world entities, making complex systems easier to design and maintain.
A class is a blueprint or template that defines the attributes and methods that all objects of that type will have. A class defines the structure but does not represent a specific instance.
An object is a specific instance of a class. Multiple objects can be created from the same class, each with their own unique attribute values.
// AQA pseudocode class definition
CLASS Animal
PRIVATE name : STRING
PRIVATE species : STRING
PRIVATE age : INTEGER
PUBLIC PROCEDURE NEW(n : STRING, s : STRING, a : INTEGER)
name ← n
species ← s
age ← a
ENDPROCEDURE
PUBLIC FUNCTION getName() RETURNS STRING
RETURN name
ENDFUNCTION
PUBLIC PROCEDURE setAge(a : INTEGER)
age ← a
ENDPROCEDURE
PUBLIC PROCEDURE speak()
OUTPUT name & " makes a sound."
ENDPROCEDURE
ENDCLASS
// Creating objects (instances)
myDog ← NEW Animal("Rex", "Dog", 3)
myCat ← NEW Animal("Luna", "Cat", 2)
OUTPUT myDog.getName() // Output: Rex
| Term | Description |
|---|---|
| Attribute | A variable belonging to a class that stores data about the object (also called instance variable or field) |
| Method | A function or procedure defined within a class that defines the object's behaviour |
| Constructor (NEW) | A special method called when an object is created; initialises the object's attributes. In AQA pseudocode, this is PROCEDURE NEW() |
Encapsulation is one of the four pillars of OOP. It is the bundling of data (attributes) and methods that operate on that data within a single class, while restricting direct access to the internal data from outside the class.
| Modifier | AQA keyword | Accessible from |
|---|---|---|
| Private | PRIVATE | Only within the class itself |
| Public | PUBLIC | From anywhere — inside and outside the class |
Since attributes are typically PRIVATE, access is provided through getter and setter methods:
PUBLIC FUNCTION getAge() RETURNS INTEGER
RETURN age
ENDFUNCTION
PUBLIC PROCEDURE setAge(a : INTEGER)
IF a >= 0 THEN
age ← a
ENDIF
ENDPROCEDURE
Instantiation is the process of creating an object from a class using the constructor (NEW). Each object is an independent instance with its own copy of the attributes.
8 questions · instantly marked · AQA 7517 standard
| Term | Definition |
|---|
10 questions · 10 minutes