It is very common in paper 2 of the IB CS exam to be asked to create UML diagrams of object clases. In these notes, we will learn how to do that.
Code
|
Diagram |
The diagram contains four important parts:
+
and -
signs tell whether each element is private (-
) or public (+
)This diagram describes all of the important features of the class without taking up nearly as much space as the full code, and is easier to interpret. Note that the constructor is NOT included - since every class includes a constructor, that wouldn’t provide any useful information.
The image above shows three classes that are interconnected. Here are some things to notice:
0..n
means “0 or more”. So you expect 2 or more employees for each flight, but only one airplane for each flight. However, an airplane can be associated with many future flights, or as few as none (perhaps if it is under maintenance). The arrows do not show you how the relationship is IMPLEMENTED, only that the relationship exists.Create potential UML diagrams to represent a Snowman
class and a Circle
class. The Snowman
object should contain AT LEAST multiple instance variables of type Circle
(e.g. head
, body
, buttons
), public method draw()
and private methods to draw the head, body, and buttons.
Look back at the Object Anatomy practice problems and make UML diagrams for every class in those problems.