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.
The example code only shows what the main function does. Therefore, all links should start in main
.I would draw the following links:
1 Playlist()
", from main
to list:Playlist
2 mp3("song1",5)
", from main
to anonymous1:mp3
3 add(anonymous1)
", from main
to list:Playlist
4 wav("song2",6)
", from main
to anonymous2:wav
5 add(anonymous2)
", from main
to list:Playlist
6 mp3("song3",7)
", from main
to anonymous3:mp3
7 add(anonymous3)
", from main
to list:Playlist
8 play()
", from main
to list:Playlist
However, the UML specification is not clear about