Object-oriented programming — AQA A-Level Computer Science
Object-oriented programming (OOP) is a programming paradigm based on the concept of objects containing data in attributes and code in methods. For AQA A-Level Computer Science, students must master encapsulation, inheritance, polymorphism, and composition versus aggregation to model real-world problems effectively.
Object-oriented programming explained
Composition means building a class from objects it holds as fields, delegating work to them, rather than extending another class to gain its behaviour.
Read the full explanation
Inheritance creates an is-a relationship, so a subclass inherits every public and protected member of its superclass whether or not it needs them, and any change to the superclass ripples into every subclass. Composition creates a has-a relationship: a Car might hold an Engine object and call engine.start() when required. Favouring composition means choosing this design when the aim is reuse of behaviour, because the parts can be swapped, tested in isolation and changed without touching the surrounding class. For example, a Logger field can be replaced with a different logging implementation at runtime, something an inheritance hierarchy fixed at compile time cannot do easily.
Your focus
- favour composition over inheritance
Object-oriented programming exam tips
Topic Overview
Object-oriented programming (OOP) is a fundamental paradigm covered in section 4.3 of the AQA A-Level specification. It shifts focus from procedural step-by-step execution to structuring software around self-contained entities known as objects, which bundle attributes and methods.
Mastering OOP is critical not only for securing marks in Paper 1 theory and coding tasks, but also for providing robust architecture in the non-exam assessment (NEA). It instils essential software engineering principles including code reusability, modularity, and maintainability.
Key Concepts
- →Encapsulation: Bundling data and methods within a class while restricting direct attribute access via access modifiers (private, protected, public).
- →Inheritance: Mechanism where a child class derives attributes and methods from a parent class, promoting code reuse and establishing an 'is-a' relationship.
- →Polymorphism: The provision of a single interface to entities of different types, primarily achieved via method overriding.
- →Composition vs Aggregation: Association models where composition indicates a strict lifecycle dependency ('death relationship') and aggregation indicates an independent lifecycle.
- →Abstract Classes and Interfaces: Blueprints that define method signatures without full implementation, mandating concrete implementation in derived classes.
Marking Points
- Explains that composition builds behaviour by holding references to other objects rather than extending a class.
- Identifies the has-a relationship in composition and the is-a relationship in inheritance.
- Notes that composition allows behaviour to be swapped or changed at runtime or without altering the enclosing class.
- Recognises that inheritance exposes a subclass to changes in its superclass, creating tight coupling.
- Justifies the preference for composition by reference to flexibility, reuse or testability, not by stating it as an absolute rule.
Examiner Tips
- 💡Use the has-a and is-a wording explicitly to show you understand the relationship each design models.
- 💡When asked to justify a design choice, name a concrete consequence such as easier testing or reduced coupling.
- 💡Avoid absolute statements; qualify the preference and acknowledge when inheritance is still suitable.
- 💡In UML class diagrams, always check line notations carefully: a solid diamond represents composition, while an unfilled diamond represents aggregation.
- 💡When asked to write OOP pseudocode, remember to explicitly declare attribute access levels as 'private' unless instructed otherwise.
Common Mistakes
- Treats composition and inheritance as interchangeable ways of writing the same code; they differ in coupling and in the relationship they model.
- Claims that inheritance is always wrong; the correct view is that it is appropriate for genuine is-a relationships with substitutable subtypes.
- Describes composition only as 'putting one class inside another' without explaining that it is used to delegate behaviour and gain flexibility.
- Believing private attributes cannot be modified at all: Private attributes can be accessed and modified, but only through public getter and setter methods within the class.
- Confusing method overloading with method overriding: Overloading involves multiple methods with the same name but different signatures within the same class; overriding involves a subclass redefining an inherited method with the identical signature.
Revision Plan
- 1Days 1-3: Review core terminology (class, object, attribute, method, encapsulation) and practice annotated UML class diagrams.
- 2Days 4-7: Focus on inheritance hierarchies, method overriding, and polymorphism, writing short code implementations in Python, C#, or Java.
- 3Days 8-10: Contrast association relationships (composition vs aggregation) and practice past Paper 1 questions comparing procedural and OOP paradigms.
Exam Question Types
- 📋UML Diagram Interpretation/Construction: Interpreting relationships, multiplicities, and class members in standard UML notation.
- 📋Pseudocode Class Design: Writing class definitions including constructors, private attributes, and overridden methods.
- 📋Comparative Essays: Discussing the trade-offs between OOP and procedural programming, or evaluating composition over inheritance.
Command Word Expectations (AQA)
Set out purposes or reasons by connecting technical principles to concrete outcomes, such as how encapsulation prevents unauthorized state corruption.
Identify both similarities and differences between two concepts (e.g., composition and aggregation), addressing both sides across explicit criteria.
How Students Lose Marks (Examiner Pitfalls)
Step-by-Step Worked Solutions
Question: A car rental company uses an object-oriented system. A base class Vehicle has private attributes registrationNumber and dailyRate. A subclass Van inherits from Vehicle and adds a private attribute payloadCapacity. Write class definition pseudocode for Van, including its constructor which initialises all inherited and new attributes.
- 1.Step 1: Declare the class Van and specify inheritance from Vehicle using appropriate pseudocode syntax (e.g., class Van inherits Vehicle).
- 2.Step 2: Declare the private attribute payloadCapacity.
- 3.Step 3: Define the constructor method (new) accepting parameters for registrationNumber, dailyRate, and payloadCapacity.
- 4.Step 4: Call the parent constructor (super) passing registrationNumber and dailyRate, then assign payloadCapacity to the instance variable.
Question: Explain the role of polymorphism in object-oriented programming and provide an example based on a base class Shape with subclasses Circle and Rectangle.
- 1.Step 1: Define polymorphism as the ability of different classes to respond to the same method call in different ways.
- 2.Step 2: Describe the base class setup with an abstract or generic method calculateArea().
- 3.Step 3: Explain how Circle overrides calculateArea() using pi * radius^2 and Rectangle overrides it using width * height.
- 4.Step 4: Conclude how a client program can iterate through an array of Shape objects and invoke calculateArea() without knowing the exact concrete subclass at compile time.