Best way to design Classes from the database?

Asked

Viewed 72 times

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’m inclined to prefer having only one User class and putting friends as a vector, but this would be a bad solution because it is inconsistent with the BD?

1 answer

2


I don’t find a bad solution... actually that’s what many Orms recommend when in the intermediate table there is nothing but two FK, each pointing to an element of the relationship.

Moreover, in this way the class becomes cleaner, and the meaning for the beholder becomes clearer.

A 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 don’t think you 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.