2
votes

What's the best way to use the composite pattern for a directed graph? The graph represents the time progress of a software . The nodes are events of the software (for example the starting of an activity). The edges are the activities , and the weight of the edge is the duration of the activity. I've ,for example , two events A and B ,and this relation:

A ----4---> B

It's mean that to complete the event A and starting B , requires 4 mseconds.

Obviously , the graph has the starting node(only outgoing edges) , the intermediate nodes , and the last node (only incoming edges).

Some ideas for the Composite Pattern?

1

1 Answers

0
votes

The composite pattern is mostly to model nested relationships, where a group of objects share the same characteristics of a single object. For the graph you're describing, I don't see any nesting or grouping that would need to be modeled like that.

Graphs can be modeled simply with a Node and an Edge classes that have the usual connections.