← VCE Software Development U3O1

OOP principle: generalisation

Finding the attributes and methods that several classes share and moving them into one more general parent class, so the code is not repeated in each specialised class.

Understanding OOP principle: generalisation in VCE Software Development U3O1

What it does: The shared attributes name and age are found in both classes and moved into the general Animal class. Dog reuses the parent's __init__ through super(), so the name and age code is written only once. The general class holds common features. The specialised class adds details for a specific type.

Common mistakes: The general parent class header is missing its colon. It should be class Animal: so the shared name attribute can be defined inside it. This only creates a local variable, so the shared attribute is never stored on the object. It should be self.reg = reg in the general parent class.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 125–141) and word search (Modules 114–141).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which statement best describes generalisation in OOP?
Moving attributes and methods shared by several classes into one parent classCopying the same attributes and methods into every class that needs them
Matches
class Student: def __init__(self, name): self.name = name class Teacher: def __init__(self, name): self.name = name
↓
Both classes repeat the same name attribute. Generalisation would move it into a general Person parent class.
Applying
Meanings
Term
generalisation
Meaning
Finding the attributes and methods that several classes share and moving them into one more general parent class, so the code is not repeated in each specialised class.
Practice
class Animal:
Testing
Gaps
Vehicle:
Check Answer
Spots
1class Animal
2 def __init__(self, name):

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Leopard' badge — Savannah Perfectionist, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which statement best describes generalisation in OOP?
A. Moving attributes and methods shared by several classes into one parent class ✓
B. Copying the same attributes and methods into every class that needs them
Generalisation finds what classes have in common and puts it in one more general parent class.
2. Dog, Cat and Bird classes each have name, age and a eat() method. What does generalisation suggest?
A. Create an Animal parent class holding name, age and eat() ✓
B. Delete eat() from two of the classes so it only appears once
The shared features belong in a general Animal class, which Dog, Cat and Bird then inherit.
3. Which is the general class and which is the specialised class?
A. Vehicle is general; Truck is specialised ✓
B. Truck is general; Vehicle is specialised
The general class holds common features. The specialised class adds details for a specific type.
4. Where should a feature that is unique to only one class, such as Bird.wingspan, be placed?
A. In the general Animal parent class
B. In the specialised Bird class only ✓
Only features shared by several classes are moved up. Unique features stay in the specialised class.
5. What is the main coding benefit of generalisation?
A. It makes every class run faster because it has more attributes
B. It reduces repeated code, so a change is made in one place ✓
Shared code is written once in the parent class, which makes the program easier to maintain.

Match the Pairs

class Vehicle: → A general parent class holding the attributes and methods shared by Car, Truck and Bike
class Car(Vehicle): → A specialised class that reuses what Vehicle provides and only adds its own extra features
Spotting common features: Dog and Cat both store a name and an age, so these shared attributes belong in a general Animal class → class Animal: def __init__(self, name, age):
Reducing repeated code: a specialised class calls the general parent class to set up the shared attributes instead of copying them → class Dog(Animal): def __init__(self, name, age): super().__init__(name, age)
class Student: def __init__(self, name): self.name = name class Teacher: def __init__(self, name): self.name = name → Both classes repeat the same name attribute. Generalisation would move it into a general Person parent class.
class Person(Student): def __init__(self, name): self.name = name → The general class is the child of a specialised class. The specialised Student should inherit from the general Person.

Key Term

generalisation
Finding the attributes and methods that several classes share and moving them into one more general parent class, so the code is not repeated in each specialised class.

Fill in the Blanks

1. class Vehicle: def start(self): print("Engine on")
Hint: Type the keyword that defines a new general parent class holding shared code.
2. class Vehicle: wheels = 4 class Car(Vehicle): pass
Hint: Type the name of the general parent class that the specialised class builds on.
3. class Bike(Vehicle): pass Bike().start()
Hint: Type the keyword that adds nothing new, because the specialised class inherits the shared method from its parent.
4. class Animal: def eat(self): print("Eating") class Cat(Animal): pass
Hint: Type the keyword that defines the shared method once in the general class, so it is not repeated in each specialised class.
5. class Pet: legs = 4 class Dog(Pet): pass print(Dog().legs)
Hint: Type the name of the shared attribute that Dog inherits from the general class.

Spot the Error

Question 1
A class Animal
B def __init__(self, name):
C self.name = name
D class Dog(Animal):
E pass
Line A — The general parent class header is missing its colon. It should be class Animal: so the shared name attribute can be defined inside it.
Question 2
A class Vehicle:
B def __init__(self, reg):
C reg = reg
D class Car(Vehicle):
E def __init__(self, reg):
F super().__init__(reg)
Line C — This only creates a local variable, so the shared attribute is never stored on the object. It should be self.reg = reg in the general parent class.
Question 3
A Class Shape:
B def __init__(self, col):
C self.col = col
D class Circle(Shape):
E pass
Line A — Python keywords are case sensitive. It must be a lowercase class, so the line should be class Shape: for the general parent class.
Question 4
A class Staff:
B def _init_(self, name):
C self.name = name
D class Teacher(Staff):
E def __init__(self, name):
F super().__init__(name)
Line B — The constructor needs double underscores on each side. It should be def __init__(self, name): so the shared attribute is set up properly.
Question 5
A class Pet:
B def speak():
C print('Hello')
D class Cat(Pet):
E pass
Line B — A method in the general class needs self as its first parameter. It should be def speak(self): so Cat can inherit it instead of repeating the code.

Student with a class code? Join your class →