Learning Objectives
By the end of this topic you will be able to:
Use and explain programming constructs: sequence, selection, iteration
Write recursive subroutines and trace their execution
Explain object-oriented programming: classes, objects, inheritance, polymorphism, encapsulation
Describe procedural and functional programming paradigms
OOP: Classes & Objects
Object-Oriented Programming
A class is a template/blueprint defining attributes (data) and methods (behaviour). An object is an instance of a class — a specific realisation with its own attribute values.
Encapsulation: combining data (attributes) and methods in one unit (the class), and hiding internal implementation details. Attributes are typically private; access is through public getter/setter methods.
Constructor: the special method (__init__ in Python) called when an object is instantiated. It initialises the object's attributes to their starting values.
Encapsulation enforces the principle of information hiding — the object's internal state is protected from direct external manipulation, reducing bugs caused by unintended modification.
OOP: Inheritance & Polymorphism
Inheritance and Polymorphism
Inheritance: a child class inherits attributes and methods from a parent (base) class. The child can override inherited methods and add its own. Promotes code reuse and a natural class hierarchy. E.g. Dog inherits from Animal.
Polymorphism: objects of different classes can be treated as objects of a common superclass, and the correct method is called depending on the actual type of the object at runtime. E.g. makeSound() behaves differently for Dog and Cat even when called via an Animal reference.
Abstract class / interface: defines a set of methods that subclasses must implement. Cannot be instantiated directly. Ensures all subclasses share a common interface even if the implementation differs.
Programming Paradigms
Procedural vs Functional Programming
Procedural (Imperative)
Program is a sequence of instructions that change program state. Uses subroutines (procedures/functions) that may have side effects. Examples: Python, Pascal. Most common paradigm learned first at A Level.
Functional
Computation as evaluation of mathematical functions. Functions have no side effects (pure functions). Use recursion instead of iteration. Examples: Haskell. Functions can be treated as values (first-class/higher-order functions), passed as arguments.
OCR H446 also expects knowledge of declarative programming (e.g. SQL, Prolog) — describing what result is required rather than how to compute it. The programmer states facts and rules; the runtime determines how to compute the answer.
Common Mistakes
Don't Lose Marks
!
Saying inheritance means "a child class IS a parent class" without qualification — always state that the child class inherits the attributes and methods of the parent class and can override them. "Inherits its code" is too vague; "inherits attributes and methods" is what OCR mark schemes reward.
!
Confusing polymorphism with overloading — polymorphism in OCR H446 context is about the same method name behaving differently depending on the object's actual type (runtime). Students sometimes describe operator overloading which is a different concept.
!
Missing the base case when describing recursion — never describe a recursive function without explicitly stating the base case (the condition that stops recursion). Without a base case, a function recurses infinitely and causes a stack overflow.