oopumlcommunication-diagram

Drawing collaboration diagram using piece of code in Java


I have to write collaboration diagram for this piece of code:

public static void main(String[] args){
Playlist list = new Playlist();
list.add(new mp3("song1",5));
list.add(new wav("song2",6));
list.add(new mp3("song3",7));

list.play();

Where mp3 and wav are classes inherited from class Track and they have constructor with two arguments. Also, function "add" takes one argument which is type Track. So, what I think is that we should have 3 self calls(for every call of method add) because that is function from class list, and then one(also self call) for function play. But not sure how to include objects of class mp3 and class wav because we are only calling functions from class Playlist. So, I am not sure why are we calling function play from class mp3(wav) and not from class playlist. And from the other side we are calling function play from playlist.


Solution

  • The example code only shows what the main function does. Therefore, all links should start in main.I would draw the following links:

    However, the UML specification is not clear about

    1. How to represent a global main function in a communication diagram.
    2. How to represent calling a constructor in a communication diagram.