Lab 12: Inheritance Diagrams
To become familiar including inheritance in UML diagrams.
For this lab you will create a UMW 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
- 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)
- And now the inheritance relationships between the classes!
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.
When you are done, please email your UML diagram to firstname.lastname@example.org.
If you are using Dia, you can email me either a .dia file, or
a .png image. If you are using something else, please send me a
Copyright © 2019 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.