Search code examples
entity-frameworkoopooad

OO design approach - Reference based approach or ID based approach


I have been doing some OO design of late. I also use EF 4.1 as the ORM. Now when i design my classes and their associations, I can think for two approaches. One is for example a Teacher teaches a subject. So Teacher class can have either a reference of the subject object as a property(reference based approach), or it can have SubjectId as a property(ID based approach). I am not sure which approach should be taken and why? I believe ID based approach is more of a relational data approach and reference based approach is true OO approach. But i am not sure.


Solution

  • If you are using JPA choose reference based approach with lazy fetching.