CIS224 Workshop 4
Interpreting class diagrams
Study each of the class diagrams given below and explain what they mean. You may use separate text and/or annotate the diagrams. Make sure you identify and explain the presence of each element in each diagram. Identify any errors and suggest any improvements.
1.
List is an interface that is derived from the interface Collection.
Collection has two abstract operation, equals and add.
List defines a new abstract operation, get.
Order is a class which requires the interface List.
Order has an attribute orderLines which is a collection of OrderLine objects.
AbstractList is an abstract class which implements the List interface.
AbstractList contains one abstract operation, get, and two methods, equal and add which are implementations of the equals and add abstract operations in the Collection interface.
The "equal" method in AbstractList should actually be called "equals".
ArrayList is a subclass of AbstractList which contains no abstract operations and which can therefore be instantiated.
The add method in ArrayList overrides the add method in Abstractlist.
(10)
2.
The Order class requires the List interface.
The ArrayList class provides (i.e., implements) the List interface.
The ArrayList class also provides the Collection interface.
(3)
3.
The association between Degree programme and Course is an aggregation.
Each Degree programme class contains a collection of 12 or more Course objects.
Each Course object can occur within 1 or more Degree programme objects.
(3)
4.
The assocation between the ChessBoard class and the Square class is a composition.
Each ChessBoard object contains 64 Square objects.
When a ChessBoard class is destroyed, the Square objects within it are destroyed along with it.
(3)
5.
An object of the Lecturer class can be the personal tutor of an object of the Student class.
When this is the case, the Lecturer object plays the role of Personal tutor and the Student plays the role of Tutee.
A Lecturer can be the personal tutor of 0 or more Students.
Each Student only has one Personal Tutor.
(4)
6.
Each Student object is associated with (is taking) 12 or more Course objects.
Each Course object is associated with (is taken by) 0 or more Student objects.
Each Course object contains an operation, getStudentList(), which returns a collection of Student objects.
The Student objects associated with a Course object can be accessed from the Course object (i.e., the association is navigable from the Course class to the Student class).
However, the diagram does not indicate that a Student object can return a list of the courses taken by that student.
The diagram could be improved by placing an open arrow head at the Course end of the association between the Student and Course classes.
An operation could then be defined in the Student class to return the list of Courses taken by a particular Student object.
(7)
7.
The association between the ChessBoard class and the Square class is a composition.
If a ChessBoard object is destroyed, all the Square objects that it owns are also destroyed.
Each ChessBoard object contains 64 Square objects that can be accessed from the ChessBoard object.
A Square object cannot send messages to the ChessBoard object that owns it.
(4)
8.
There is a qualified association between a ChessBoard object and a Square object.
There is a single Square object associated with each distinct pair of values for the row and column attributes in a ChessBoard object.
The row and column attributes can each take integer values between 1 and 8, inclusive.
(3)
9.
A Copy object can be associated with 0 or 1 Book objects.
A Copy object can be associated with 0 or 1 Journal objects.
For each Book object, there can be 1 or more Copy objects associated with it.
For each Journal object, there can be 1 or more Copy objects associated with it.
There is a constraint on the associations between the Copy class and the Book and Journal classes.
A Copy object can be associated with a Book object or a Journal object, but not both.
(6)
10.
There is a qualified association between Order and OrderLine.
For each Product, there may (or may not) be a single OrderLine object associated with that Product in an Order object.
Each OrderLine object contains an attribute, quantity.
Messages can be sent to OrderLine objects from the Order object that owns them.
(4)
11.
A MemberOfStaff object may borrow up to 12 Copies.
A MemberOfStaff object may borrow up to 12 Journals.
There is a constraint on the associations between the MemberOfStaff, Copy and Journal classes.
The sum of the number of Copies borrowed by a MemberOfStaff and the number of Journals borrowed by a MemberOfStaff must be less than or equal to 12.
Each Journal is associated with 1 MemberOfStaff.
Each Copy object is associated with 1 MemberOfStaff.
It is an error to state that each Journal object is associated with 1 MemberOfStaff. The multiplicity at the MemberOfStaff end of the association between Journal and MemberOfStaff should be "0..1", since a Journal object may not be on loan to anyone.
It is an error to state that each Copy object is associated with 1 MemberOfStaff. The multiplicity at the MemberOfStaff end of the association between Copy and MemberOfStaff should be "0..1", since a Copy object may not be on loan to anyone.
(8)
12.
The association between the Student class and the Course class indicates that Students take Courses.
The association between the Lecturer class and the Course class indicates that Lecturers teach Courses.
There is a derived association between the Lecturer class and the Student class which indicates that Lecturers teach Students.
This derived association can be inferred from the other associations in the diagram. There is therefore no need to consider separately how to implement this association.
(4)
13.
Each Student object is associated with 12 or more Result objects.
Each Student is associated with 12 or more Course objects.
Each Result object is associated with a single Course
Each Result object is associated with a single Student.
Each Course object is associated with 0 or more Results.
Each Course object is associated with 0 or more Student objects.
Each Result object has two integer attributes, mark and year.
(7)
14.
Each Copy object is associated with a single MemberOfStaff.
This is an error - it is possible for a Copy object not to be associated with anyone. The multiplicity at the MemberOfStaff end of the association between Copy and MemberOfStaff should therefore be 0..1.
Each MemberOfStaff object has up to 12 Copy objects.
There is an association class on the association between the Copy and MemberOfStaff classes.
Each instance of this association class represents a link between a specific Copy object and a specific MemberOfStaff object.
This association class has two Date type attributes, dateOut and dateDue, and an operation, getFine() which returns a value of type Money.
Each Copy object is a copy of exactly 1 Item object.
Each Item object may have 1 or more Copy objects associated with it.
The Journal class is a subclass of Item.
The Book class is a subclass of Item.
Possible error - Item should be an interface since every item will be either a Journal or a Book.
(11)