Stefano Scerra
Stefano Scerra

Reputation: 123

Graph node and edge modeling in UML diagram

What would be the most correct/elegant way to model the relationship between a graph edge class and a node class in a UML class diagram?

I would normally use two associations Edge->Node, one for the source node role and one for the destination node role. But recently I've come up with this kind of diagram for a project:

class diagram

Is the use of an aggregation considered to be correct in this case?

Upvotes: 0

Views: 2642

Answers (2)

Ladislav Zitka
Ladislav Zitka

Reputation: 1000

Although many years later here is more detailed idea about how to model graphs in UML.

I need to model both relational and graph structures, the visual tools for relational modeling and data mapping are quite strong, while we don't have much for graphs. So I was searching how to use one model type to cover both scenarios... and found this approach which looks to me from first look simple and robust enough.

The general idea is to make common graph schema representation which is robust enough to create any kind of graph instances as can be seen on following picture which defines generic meta-model structure: enter image description here

NOTE: As can be seen the metamodel reflects Neo4j and OrientDB implementation, so other graph databases might vary a bit (for example on properties being bounded to only vertices and not edges, etc.)

Ok, so we have metamodel, now it looks more or less clear, but how to use it to describe real use scenario?: enter image description here

So what is this secondary picture? It is the Graph ontology definition and that is the real result required for any kind of graph based project, to properly reflect the real world in graph.

Upvotes: -2

Spaceman Spiff
Spaceman Spiff

Reputation: 934

Yes your use of aggregation is correct in this example provided that an edge must have exactly two nodes.

The only thing I might add is that your Node could also potentially have a one to many relationship with your edge class, although that is not reflected in the fields of your class diagram currently.

Upvotes: 3

Related Questions