rtxa
rtxa

Reputation: 56

How to show object assignment in a collaboration diagram?

I wonder how to show object assignment in the collaboration diagram I made with this given code, in particular in aNode = path.getLastPathComponent().

/* @author Scott Violet */ 
public class SampleTreeModel extends DefaultTreeModel {
 
    public SampleTreeModel(TreeNode newRoot) { super(newRoot); } 
    public void valueForPathChanged(TreePath path, Object newValue) {
        DefaultMutableTreeNode aNode =
           (DefaultMutableTreeNode)path.getLastPathComponent(); 
        SampleData sampleData = (SampleData)aNode.getUserObject(); 
        sampleData.setString((String)newValue); 
        if (this.isColorGreen) sampleData.setColor(Color.green); 
        else sampleData.setColor(Color.black); 
        nodeChanged(aNode); 
    } 
}

I tried showing the assignment like in the code, but not sure if that is the correct way, maybe the relationships with the objects make this implicit. Hope you can help me. Thanks!

enter image description here

Upvotes: 3

Views: 80

Answers (1)

Axel Scheithauer
Axel Scheithauer

Reputation: 3625

I think, this is the correct way. The assignment target is shown in front of the equals sign. If you wanted to specify the returned value, it would be shown after a colon behind the label of the reply message.

However, I have some remarks on the diagram:

  • The names of the lifelines (the boxes) should not be underlined.
  • Messages 2 and 3 use a dot notation to denote the target. This is not allowed and anyway superfluous, since the messages are visually connected to the target.
  • The assignment is part of the reply message. This would be shown with a dashed arrow. There should be reply messages for all assignments additionally to the request messages. This is the official rule. However, for simple query-operations I think it is ok to show it like you do.
  • I think your message 1 shows a list of parameters without specified arguments. Then they should be omitted. If you still want to show them, they must be shown appended with "=-". This means the interaction doesn't depend on the concrete value given here.
  • Your custom stereotypes «local» and «parameter» are assigned to messages. I think they apply to the lifelines, or not?

Upvotes: 3

Related Questions