What collection works best for maintaining a family tree, where each node can have multiple parents and multiple children, spouse relationships, etc.?

Joseph Shelby

With Collections by themselves, there isn't one. What you're asking for is a Labeled Directed Graph (A directed graph where the graph edges have labels describing the relationship). A rather complex object.

You'd have to design that yourself (though you can use Collection objects like Lists in the implementation as a convenience), and design Comparators to support your final implementation classes of a "FamilyTreePerson" for sorting purposes (like sort by name or sort by birthdate, etc.).

After that, you have to decide what "Iteration" over the tree really means and define Iterator classes over the Graph. After that, completing the Collection interface should be pretty simple.

In other words, you've got a lot of design work to do, but designing it well can lead to a rather flexible framework (or at least a source of Patterns) for future use. In particular, keep in mind in building such a LabeledDirectedGraph beast on how you can keep "Family Tree" concepts out of it. The Label provider should be an Interface function object, like Comparator.

This is getting heavily into "Generic Programming", and I advise you read more about that (most GP work is being done in connection with the STL from C++).

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact