jfkint
jfkint

Reputation: 119

uml - Class diagram of node-edge relation

I'm trying to create a class diagram for a node-edge relationship, as it would be found in a directed graph. I want to convey that Nodes have references to Edges, and Edges also have references to Nodes. Every Edge needs exactly two Nodes (source and target).

Would this be an acceptable way to model this?

class diagram node-edge

Upvotes: 3

Views: 584

Answers (1)

Christophe
Christophe

Reputation: 73406

Yes, this diagram expresses perfectly what you describe in the text. The doubled association is right: each association expresses something different.

You are somewhat more precise in the diagram than in the text, since you show that each node has inEdges and outEdges, whereas the text just mentions the reference to Edges without being more explicit.

A common variant for the implementation of directed graph is that the Node knows only its outEdges. If this is important, you may express it with navigability, with an arrow in direction of sourceNode and a cross on the side of inEdges. But this practice is relatively rare in the model.

For an undirected graph, you could have only one association with a multiplicity of 2 on the side of the nodes.

Upvotes: 4

Related Questions