Object-Oriented Programming

💻 Computer Science Years 10–11 Foundation

OOP bundles data (attributes) and behaviour (methods) into objects; a class is a blueprint and an object is an instance made from it, with encapsulation and inheritance as core ideas.

Open this lesson, with practice and a printable worksheet →

A cookie cutter is not a cookie. The cutter is a shape — press it into dough and you stamp out as many cookies as you like, each the same shape but its own biscuit. In programming this idea is object-oriented programming (OOP). A class is the cutter (a blueprint), and each object is a cookie stamped from it. OOP bundles a thing's data and its behaviour together, so related code lives in one tidy place.

Why this matters: Most large software — games, apps, websites — is built from objects. Modelling real things (a player, an account, a dog) as objects keeps programs organised and easy to extend. OOP is a core idea on every GCSE specification.
Class: Dog blueprint name, age bark() Object: rex name="Rex", age=4 Object: bella name="Bella", age=2
One class (blueprint) stamps out many objects (instances).

Class versus object

A class defines what a kind of thing has and can do — but it is only a plan. An object (also called an instance) is a real, working copy made from that class, with its own values. From one Dog class you can create many dogs, each remembering its own name and age.

Attributes and methods

Inside an object are two kinds of thing. Attributes (also called properties) are the data — the facts it stores, like name and age. Methods are the behaviour — the actions it can do, like bark(). Keeping data and the code that acts on it together in one object is called encapsulation.

Object Attributes = data name, age Methods = actions bark(), sit()
An object bundles its data (attributes) and its actions (methods) together.

A Dog class in pseudocode

Here is a simple Dog class. The constructor sets the starting attributes; bark() is a method:

class Dog
    name
    age
    procedure bark()
        print(name + " says Woof!")
    endprocedure
endclass

rex = new Dog("Rex", 4)
bella = new Dog("Bella", 2)
rex.bark()      # Rex says Woof!
Dog name : string age : integer bark() attributes above, method below
The Dog class: attributes name and age, plus a bark() method.
TermMeansDog example
ClassBlueprint / planDog
ObjectAn instance made from a classrex, bella
AttributeData the object storesname, age
MethodAn action the object can dobark()

Inheritance — reusing a parent's features

A class can be built from another. A subclass (child) inherits the attributes and methods of its parent (superclass), then adds its own. So Dog and Cat might both inherit shared features like name and age from a general Animal class — write the shared parts once, reuse them everywhere.

Animal name, age, eat() Dog + bark() Cat + meow()
Dog and Cat inherit shared features from Animal, then add their own.
Worked reasoning: From the Dog class we make two objects. rex = new Dog("Rex", 4) creates one dog whose name is "Rex" and age is 4. bella = new Dog("Bella", 2) creates a separate dog. They share the same class (so both can bark()), but each keeps its own attribute values — changing rex.age does not touch bella.age.
Common mistake: Confusing a class with an object. The class is the blueprint written once; an object is a working instance made from it. Saying "Dog barked" is wrong — it is rex (an object) that barks, using the method the Dog class describes.

Memory hook: Class = cutter, object = cookie. An object holds Attributes (data) and Methods (actions) together (encapsulation), and a subclass inherits from its parent to reuse shared features.

Get the printable worksheet →
← Recursion → JavaScript Basics
← Sasta Basta home All subjects