Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Don't use the id's man, this is just a bad idea for all the reasons mentioned. You'll lock yourself into a design. Let me give an example.</p> <p>Right now you define you're Membership as a mapping between Clubs to People. Rightfully, your Membership should be a map of Clubs to "Members", but you are assuming that all Members are People and that since all of the people id's are unique you think you can just use the ID. </p> <p>But what if in the future you want to extend your membership concept to "family memberships", for which you create a Family table and a Family class. In good OO fashion you extract an interface of Family and Person called Member. As long as both classes implement the equals and hashCode methods properly, no other code will have to be touched. Personally, I would have defined the Member interface right up front.</p> <pre><code>public interface Member { } public class Person implements Member { private int id; // primary key private String name; } public class Family implements Member { private int id; private String name; } public class Club { private String name; // primary key } public class Membership { private Member member; private Club club; private Date expires; } </code></pre> <p>If, you had used ID's in your interface, you will either need to enforce cross-table uniqueness of key values, or maintain two separate Maps and forgo the nice polymorphic interface stuff. </p> <p>Believe me, unless you are writing one-off, disposable applications, you want to avoid using ID's in your interface.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload