Skip to topic
    ← Back to course topics

    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

    1. 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
    1. 1Days 1-3: Review core terminology (class, object, attribute, method, encapsulation) and practice annotated UML class diagrams.
    2. 2Days 4-7: Focus on inheritance hierarchies, method overriding, and polymorphism, writing short code implementations in Python, C#, or Java.
    3. 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)
    Explain

    Set out purposes or reasons by connecting technical principles to concrete outcomes, such as how encapsulation prevents unauthorized state corruption.

    Compare

    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)
    Pitfall: Confusing composition and aggregation when explaining object relationships.
    ❌ Weak Answer (Loses Marks):Aggregation and composition both mean that an object contains another object.
    Example improved answer:Both represent 'has-a' relationships between objects. In composition, the contained object's lifecycle depends directly on the container object; if the container is destroyed, the contained object ceases to exist. In aggregation, the contained object has an independent lifecycle and can continue to exist even if the container object is destroyed.
    Examiner Tip: Always specify the lifecycle dependency when contrasting composition and aggregation to secure all marks.
    Pitfall: Vaguely defining encapsulation as simply 'hiding code' or 'making things private'.
    ❌ Weak Answer (Loses Marks):Encapsulation is when you hide data so hackers cannot see it.
    Example improved answer:Encapsulation is the bundling of data attributes and the methods that operate on them into a single unit or class, restricting direct access to some of the object's components by making attributes private and accessing or modifying them solely via public getter and setter methods.
    Examiner Tip: Use the terms 'attributes', 'methods', 'private', and 'public interface' explicitly in your definition.
    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. 1.Step 1: Declare the class Van and specify inheritance from Vehicle using appropriate pseudocode syntax (e.g., class Van inherits Vehicle).
    2. 2.Step 2: Declare the private attribute payloadCapacity.
    3. 3.Step 3: Define the constructor method (new) accepting parameters for registrationNumber, dailyRate, and payloadCapacity.
    4. 4.Step 4: Call the parent constructor (super) passing registrationNumber and dailyRate, then assign payloadCapacity to the instance variable.
    Final Answer: class Van inherits Vehicle private payloadCapacity : Real public procedure new(givenReg, givenRate, givenCapacity) super.new(givenReg, givenRate) payloadCapacity = givenCapacity endprocedure endclass

    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. 1.Step 1: Define polymorphism as the ability of different classes to respond to the same method call in different ways.
    2. 2.Step 2: Describe the base class setup with an abstract or generic method calculateArea().
    3. 3.Step 3: Explain how Circle overrides calculateArea() using pi * radius^2 and Rectangle overrides it using width * height.
    4. 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.
    Final Answer: Polymorphism enables a single method identifier to exhibit different behaviours depending on the object it is invoked upon. In a Shape hierarchy, both Circle and Rectangle override an inherited calculateArea() method. A list of Shape references can execute shape.calculateArea() dynamically, invoking the correct subclass logic via late binding.
    Active Recall Memory Test
    What is the defining distinction between composition and aggregation?
    Key Fact: In composition, child objects cannot exist independently of the parent object; in aggregation, child objects have an independent lifecycle.
    Which OOP mechanism allows a derived class to provide a specific implementation of a method declared in a superclass?
    Key Fact: Method overriding (a form of polymorphism).
    What access modifier should be applied to an attribute to prevent direct access outside its class?
    Key Fact: Private.
    Frequently Asked Questions
    What is the difference between a class and an object?
    A class is a blueprint, template, or abstract data type definition that specifies the attributes and methods that its instances will possess. An object is a concrete, instantiated instance of that class residing in memory during runtime. Multiple distinct objects can be instantiated from a single class blueprint.
    Why would a programmer prefer composition over inheritance?
    Composition is often preferred because it offers looser coupling and greater design flexibility. Inheritance tightly couples a subclass to its superclass, meaning changes to the parent can unintentionally break child implementations. Composition builds complex types by combining independent components, making code easier to test and modify.
    Do I need to know a specific programming language for AQA OOP exam questions?
    No single language is required for Paper 1 written theory. AQA accepts standard pseudocode matching their specification style guide, as well as mainstream high-level languages like Python, C#, Java, or VB.NET. The key requirement is demonstrating correct OOP logic, access levels, and inheritance structure.
    What does the constructor method actually do?
    A constructor is a special subroutine invoked automatically when an object is instantiated. Its main role is to allocate resources and initialise the object's attributes to valid starting values, often taking parameters provided at creation.