Best way to design Classes from the database?

4

What is the best way to design Classes from the Database schema below:

Usuario(id INTEGER PK, desc TEXT);
Amigo(idA INTEGER, idB INTEGER, PK(idA,idB), FK(idA) REFERENCES Usuario(id));

This means that a user has 0 or more friends, when designing the classes in this case, I am inclined to prefer to have only one User class and put friends as a vector, but this would be a bad solution because it is inconsistent with the DB ?

    
asked by anonymous 27.03.2015 / 23:22

1 answer

2

I do not think it's a bad solution ... in fact that's what many ORMs recommend when the middle table is nothing but two FKs, each pointing to an element of the relationship.

In addition, this way the class gets cleaner, and the meaning for the viewer becomes clearer.

One person has a list of friends ... simple.

Unless you want to qualify friendships (good friendship, bad friendship, childhood friendship, etc.), which is not the present case, I do not think it should complicate something, just because it could be otherwise . Stick to the facts, in your model friendships are not qualified and ready. If one day this changes, go there and change the classes.

    
27.03.2015 / 23:36