Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ORM - POJO Composition Vs Inheritance

 
Abhishek khare
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently writing a complete new application, I am planning to use Hibernate for ORM.

The Question is when designing the POJO for the App, should we prefer Composition or Inheritance.

It will be helpful, if some one can explain the Advantage and Disadvantage of both and scenario when either should be used.

Thanks In Advance.

 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would drop the ORM and hibernate out of this question and ask it in the OO, Patterns, UML and Refactoring forum. One of the purposes of an ORM framework is to be able to write your application in terms of the domain without having to worry about tables, columns, and keys. That said your question should really be:

For <insert your specific use case here> is composition or inheritance more appropriate?

That said the general consensus is to prefer composition to inheritance, but that is not to say inheritance does not have a place. Also this is not the forum for that discussion.

From an ORM perspective composition is less complicated but once again that is not to say inheritance does not have its place. I know that this was kind of a sideways answer to your question but I would not let a framework determine whether you use composition or inheritance. That should be determined by your use case and your domain.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic