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.
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.
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!
| Term | Means | Dog example |
|---|---|---|
| Class | Blueprint / plan | Dog |
| Object | An instance made from a class | rex, bella |
| Attribute | Data the object stores | name, age |
| Method | An action the object can do | bark() |
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.
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.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.