COS3711
Assignment 1
2026
, COS3711 – Advanced Programming | Assignment 1 (2026)
COS3711 – Advanced Programming
Assignment 1 – 2026
Design Patterns | Computer Science Department | UNISA
Year Module
Question 1 – Vehicle Class Hierarchy (OOP Design)
This solution implements a class hierarchy for managing vehicle details using Qt's parent-
child mechanism. The design follows OOP principles including encapsulation, inheritance,
and avoidance of code duplication.
1.1 Design Overview
The class hierarchy is:
• Vehicle (abstract base class) – holds model (QString) and year (int) with validation
• PassengerVehicle (derived) – adds numberOfPassengers (int)
• TransportVehicle (derived) – adds carryingCapacity (double, in kg)
Qt's parent-child facility is used: all Vehicle objects are created with a parent QObject. A
QObjectList stores pointers to the vehicles. When the parent is destroyed, all children are
automatically cleaned up.
1.2 vehicle.h
#define VEHICLE_H
#define VEHICLE_H
#include <QObject>
#include <QString>
Assignment 1
2026
, COS3711 – Advanced Programming | Assignment 1 (2026)
COS3711 – Advanced Programming
Assignment 1 – 2026
Design Patterns | Computer Science Department | UNISA
Year Module
Question 1 – Vehicle Class Hierarchy (OOP Design)
This solution implements a class hierarchy for managing vehicle details using Qt's parent-
child mechanism. The design follows OOP principles including encapsulation, inheritance,
and avoidance of code duplication.
1.1 Design Overview
The class hierarchy is:
• Vehicle (abstract base class) – holds model (QString) and year (int) with validation
• PassengerVehicle (derived) – adds numberOfPassengers (int)
• TransportVehicle (derived) – adds carryingCapacity (double, in kg)
Qt's parent-child facility is used: all Vehicle objects are created with a parent QObject. A
QObjectList stores pointers to the vehicles. When the parent is destroyed, all children are
automatically cleaned up.
1.2 vehicle.h
#define VEHICLE_H
#define VEHICLE_H
#include <QObject>
#include <QString>