Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools

Assignment 02: Objects and Classes

Release date: Tuesday, 14.04.15 - Due date: Sunday, 19.04.15, 23:59

Read the formal conditions on your submissions to make sure that the tutors can accept your solutions.
How to draw an Object Diagram? Create a Class Diagram with astah. In the middle of the tool bar you find the “InstanceSpecification” and directly next to it the “Link”. These are the ingredients of an Object Diagram. For an instance of an Association Class it is ok to place it just next to the corresponding link, as it seems to be impossible to connect it with the link. (Other solutions are welcome, but be ready to explain how it should be. If you don't use astah, but provide a PDF or PNG, this is OK this time as well.)

Task 04: Aggregation vs Composition

2 points

Give us four examples of a part-whole relationship, two examples of an aggregation and two examples of a composition relationship. Argue for each of the four cases why it is an aggregation or an composition respectively. (Such an argument would consist of the generic criterion for choosing the respective type of association and one or two sentences arguing why the criterion applies here.)

[Optional, 0 points]: Can you find an example where it depends on the context whether it is an aggregation or composition.

Task 05: Gangsters are Persons

9 = 5 + 4 points

Studying class diagrams can be as exciting as hunting down gangsters. This task is the proof. Below you find a class diagram explaining that gangsters are persons and that certain associations are possible between gangsters and persons:

Associations between Persons and Gangsters

Study the class diagram carefully and understand which associations can connect objects of which class. With this knowledge you can easily solve the following two subtasks.

Some Persons and Gangsters

a) Study the object diagram carefully and tell us:

  1. Who is for sure a gangster? How can you say?
  2. Who is for sure a person? How can you say?

Make sure that you don't accuse a person of being a gangster, if you can not be sure. Accusing a person that might still be person will cost you a point per wrong accusation!

Two Persons and two Gangsters

b) For the four persons above we know already whether they are gangsters or just persons. Given the class diagram above, which associations are possible between the following pairs (in the indicated direction)?:

  1. Alonso → Bambino
  2. Bambino → Carlo
  3. Carlo → Donato
  4. Donato → Alonso

Name all possible associations.

Task 06: Seeing objects

12 points

Enjoy the beautiful drawing we created for you with JHotDraw 5.11)

Drawing created with JHotDraw 5.1 in a running JavaDrawApp

The goal of this task is to give you a first feeling about how classes, objects and the implementation relate to each other.

If you enjoyed the drawing long enough, check out the following projects/files:

  • The file A02T06_JHotDrawFigures.astah from your Assignment02-GXY folder.
  • The file oosc-is-ok.ser from the same folder.
  • The complete source code of the JHotDraw 5.1 project. Add the following URL as new repository location and check out this repository as a whole:

We are only interested in the classes and interfaces that are already shown in the class diagram in your file. Explore the source code2) in the package CH.ifa.draw.figures and add the following to the class diagram:

  • All generalization (extends) and implementation (implements) relationship between these classes and interfaces.
  • All associations between these classes and interfaces (fields having one of these classes or interfaces as type).

Ignore the static fields, ignore the transient fields, ignore the fields related to serialization (field names contain “serial”). You don't need to add any attribute, just add associations.

Now complete the “Object Diagram” so that it shows all the objects and their attribute values in the drawing that we created. You already find a few “instance specifications” (=“objects”) in the file. You are free to guess the coordinates and the color (names), but be consistent. Make sure that you represent all the objects in the drawing. The class diagram should be helpful for that.

As solution we expect your updated A02T06_JHotDrawFigures.astah file in your Assignment02-GXY folder. Keep the source code of JHotDraw just in your workspace, we don't need it in the repository.

For the curious: You can load the drawing oosc-is-ok.ser into the application. You find in the package CH.ifa.draw.samples.javadraw. Right click on the file and select “Run As …” > “Java Application”.3)

Task 07: Association Classes (optional)

[4+2 points]
Two ways to model employment
Two ways to model appointments

Give us for each of the four class diagrams above:

  • An object diagram that is compatible with the class diagram.
  • Provide for the fourth class diagram an object diagram that violates the third class diagram.

(even more optional) We claim that the two last diagrams are equivalent.

  • Describe the exact conditions under which using an association class is equivalent to having a class between the two associated classes.
  • Give a (semi-formal) proof of the equivalence.
Version 5.1 is probably the oldest version of JHotDraw available. Nevertheless we feel that is the best version for educational purposes, at least at the beginning. Already the next versions while gaining features loose some design quality.
Experts might want to try the following Keyboard-Shortcuts: F3 (on a class, field or method name), F4 (on a class name), Ctrl-O (anywhere in class), Ctrl-T (on a class name), Ctrl-Shift-G (on a class, field or method name), Ctrl-Shift-T (anywhere).
Experts might want to use the debugger. Set a breakpoint in line 608 of, start with “Debug As …” , load the drawing file, switch to the Debug perspective and explore this.fDrawing. It's a bit more complicated than you might expect, but with some endurance you find the information. And there other tricks to get the data…
teaching/lectures/oosc/2015/assignment_02.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2024