Lab 10: Inheritance Diagrams
Objective
To become familiar including inheritance in UML diagrams.
Task
For this lab you will create a UML class diagram for a program which uses
geometric shapes. You will have the following classes:
- Shape, which has a field called "name", and methods called
"getArea" and "display". getArea should return a double. It has a constructor
which takes the name as a parameter.
- Circle, which is a subclass of Shape. It adds a field
called "radius". It overrides the getArea method, and also adds a method
called "getCircumference". It's constructor takes the name and radius.
- Polygon, which is a subclass of Shape. It adds an int
field called "numSides". It also adds a method called "getPerimeter", and
another called "getNumSides". It's constructor takes the name, and number of
sides as parameters.
- Rectangle, which is a subclass of Polygon. It
adds double fields called "length" and "width". It also overrides the
getArea and getPerimeter methods. Its constructor takes in the name, length
and width.
- Triangle, which is also a subclass of Polygon. It
adds double fields called "base" and "height". It overrides the
getArea and getPerimeter methods as well. Its constructor takes the name,
base and height as parameters.
Remember to include all the things needed in a class diagram:
- Private data fields (with names and types)
- Methods (with names, parameter types and return type)
- Constructors
- And now the inheritance relationships between the classes!
Dia Inheritance
To draw an inheritance arrow in Dia, you use the arrow labelled
"Generalization, class inheritance". Make sure the arrow is going the right
way! The arrow head should point at the base class.
Submitting
When you are done, please upload your UML diagram to Canvas.
If you are using Dia, you can upload either a .dia file, or a .png image.
If you are using something else, please upload a .png
Copyright ©
2024
Ian Finlayson | Licensed under a Creative Commons BY-NC-SA 4.0 License.