Relations in the UML Class Diagram

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

The Tree object has a pointer to a Node (its root), which, I believe, defines a one-way relationship (Tree ->Node) with a short 1..1 at both ends. Correctly?

Each Node object has pointers to edges that exit from it (Edge objects). Since these edges only exist if Node exists, I believe this is a compositional association.

But then every Edge object has a pointer to the edge's Node target. How can I imagine this relationship, given that I already have the Edge Node composition ->described above?

Also, if you are still reading :), each Node has a pointer to its parent Node. Here I would use a one-way unary connection, but I do not know what name to use for this relationship.

Thanks for any help.

+3
source share
4 answers

I would say that:

  • The tree has a root node
  • Nodes have child nodes
  • Nodes can have a parent node

Note:

  • You might want to distinguish between a UML class diagram and a UML object diagram.
  • , root node child node ( node root node, node , node)

Edge : Edge Node.

+1

, , UML:

Tree -> Node, aggregation, 1..0-1
Node -> Edge, aggregation, 1..*
Edge -> Node, composition, 1..2 (an edge exists only if it connects 2 nodes)
Node -> Node, aggregation, 1..1 (would be composition, except the root node doesn't point to a node.

. , , , .

+1

- Tree Node ( ), , , --association ( → Node) 1..1 . ?

, 0..1 - 1 ( )

, Edge . - (.. ),

+1

OO Composite .

, . , , , , .. / .

0

Source: https://habr.com/ru/post/1718966/


All Articles