Relationships in a UML class diagram

class-diagramrelationshipuml

I have an application that models a tree, with classes Tree, Node and Edge (I need the Edge class!), and I'm not sure how to represent the relationships in the class diagram for this. I've read other posts about this, but am still in doubt.

The Tree object have a pointer to a Node (its root), which I believe defines an one-way association (Tree -> Node) with multiplicity 1..1 in both ends. Is it right?

Each Node object have pointers to the edges that comes out of it (Edge objects). Since these edges only exist if the node exist, I believe it's a composition association.

But then I have, in each Edge object, a pointer to the target Node of the edge. How can I represent this relationship, considering I already have the Node -> Edge composition described above?

Also, if you're still reading :), each Node have a pointer to its parent Node. Here, I would use an one-way unary association, but I don't know which name to use for this relationship.

Thanks for any help.

Best Answer

I'd say that:

  • A tree has a root node
  • Nodes have child nodes
  • Nodes may have a parent node

Note:

  • You might want to distinguish between a UML class diagram versus a UML object diagram
  • I don't know whether root node and child node are the same class (a child node might be a subclass of root node, because both types of node have children but only child nodes have a parent node)

Edge might not be a class at all: instead an Edge might just be an instance of a Node.

Related Topic