SE-2811 Software Component Design
Lab 1:
Inheritance

The objective of this lab is to review and use object-oriented principles to design and implement classes to meet specific purposes

Assignment

Consider the following class diagram illustrating the relationships between various types of vehicles:

In this system, you are allowed to create instances of Car, Convertible, Pickup, and Dumptruck. Vehicle is an abstract concept, so you shouldn't be able to instantiate one of those. By the way, Vehicle might be an interface, abstract class, or maybe even a regular class - it's not clear from the above diagram. All vehicles can start(), stop(), goForward(), and goBackward(). Vehicles such as Convertible and Dumptruck have the additional behaviors shown in the class diagram.

Suppose you want to introduce the ability for the Dumptruck, the Pickup, and the Convertible (as shown below) to plow snow. We don't want a Car that can plow snow, because that would be silly.

Image result for convertible with plow

 

 Any vehicle that can plow has some additional behaviors: raisePlow() and lowerPlow(). It also has an additional attribute: plowWidth.

Your job is to consider the given design in the class diagram above, and figure out what additional classes (or abstract classes or interfaces) you'd need in order to be able to create instances of these additional vehicles. Use the object-oriented design techniques you learned about in SE101x, such as eliminating duplicate code whevever possible, leveraging inheritance, etc. Note that the given diagram may not exhibit the best o-o design techniques!

Use Enterprise Architect to create the expanded-capability class diagram. Make corrections/improvements to the base class diagram as you create your new diagram.

When you are done, write a simple VehicleApp class contains a main class and main() method that creates various types of vehicles and calls their respective methods. From within VehicleApp, you should still be able to create instances of regular Cars, Convertibles, Pickups, and Dumptrucks in addition to being able to create instances of specialized versions of Convertibles, Pickups, and Dumptrucks that can also plow.

Note that there are no constructors defined in the above class diagram, so you'll have to add those where appropriate. You must also add accessor methods so that you can query a vehicle for the values of its attributes (e.g. you need a a getWeight() method that you can call for all vehicles, and a getLoadCapacity() method you can call on Pickup and Dumptruck vehicles (and any vehicles that are subtypes of those).

you should not be able to call raisePlow() or lowerPlow() on any vehicle except for those that can plow.

you should not be able to call raiseRoof() or lowerRoof() on any vehicle except for Convertibles (or their subtypes).

you should not be able to call raiseLoad() or lowerLoad() on any vehicle except for Dumptrucks (or their subtypes).

 

Lab Submission (due by end of lab)

Your assignment will consist of:

Submit your assignment according to your instructor's specific requirements.