Computer Science – 20.1 Programming Paradigms | e-Consult
20.1 Programming Paradigms (1 questions)
Login to see all questions.
Click on a question to view the answer
To model a vehicle management system using OOP, I would create the following classes:
| Class Name | Attributes | Relationships |
| Vehicle | make, model, year, registration number, mileage | Abstract class - base for other vehicle types. |
| Car | fueltype, numberofdoors, enginesize | Inherits from Vehicle. |
| Truck | cargocapacity, numberof_axles | Inherits from Vehicle. |
| Motorcycle | enginecapacity, numberof_wheels | Inherits from Vehicle. |
Relationships:
- Inheritance: Car, Truck, and Motorcycle would inherit from the
Vehicleclass. This allows them to share common attributes (like make, model, year) and methods (like start, stop). - Composition/Aggregation: A
Vehicleclass might have a composition relationship with aEngineclass. TheVehicle*contains* anEngine. This would allow for more complex vehicle models in the future.
This design demonstrates abstraction by hiding the specific details of each vehicle type within its respective class. Polymorphism is demonstrated by the ability to treat any Vehicle object as a Vehicle and call a common method like start() or accelerate(). Encapsulation is achieved by controlling access to the vehicle's attributes through getter and setter methods.