So I was pondering about certain problem involving serialization of objects to relational databases.
Let's say you have N different objects, all implementing a certain interface (a directed graph interface for that matter. they provide methods such as getIncomingNodes() , getOutgoingNodes()).
If each such object has a corresponding table in a relational database, What's the best practice of serializing such a directed graph to a relational database?
Assuming N is small, (in my case, N=3) I decomposed all possible links to be contained in a separate table. For example, A table of links directed from object x to y will be similar to:
tbl_links_X_Y {
int X_id
int Y_id
}
Problem is , you get N^2 such tables - not very efficient, and could prove difficult to extend in the future to N+1 objects.
Is there any pattern that solves that issue? (even if it does not involve relational databases, I would be happy to hear...)
Thanks!o