1

I have made an app and I experimented in two scenarios. Make a bean extend a Hibernate db object, or make the bean clear distinct from db object. In the first case, I had a quick way to access data. A quick way to make interfaces in the end of different beans extending the same db table. In the second case, I had to load the external inside the beans and go on.

Which way is the "by-the-book" way? Both seemed pretty nice, but I liked the first. Or shouldn't I ?

hephestos
  • 434
  • 1
  • 6
  • 19
  • example code is not necesary, it's a general question for programming development and engineering of software. There is no use to provide source code. – hephestos Jan 28 '11 at 11:33
  • There is use to provide code. It will clarify your question. – Don Roby Jan 28 '11 at 12:04
  • @hephestos: http://stackoverflow.com/faq - When you have decided which answer is the most helpful to you, mark it as the accepted answer by clicking on the check box outline to the left of the answer. This lets other people know that you have received a good answer to your question. Doing this is helpful because it shows other people that you’re getting value from the community. (If you don’t do this, people will often politely ask you to go back and accept answers for more of your questions!) – skaffman Jan 28 '11 at 19:03
  • @skaffman, thank you for the remind. I will surely would like to do it. If that is the case. In the meantime I should let it open. I think. – hephestos Jan 31 '11 at 11:29
  • @hephestos: The point is that you've asked 7 questions before this one, and accepted none of the answers. This discourages people from answering any new ones you post. You need to go back and accept answers to your prior questions. – skaffman Jan 31 '11 at 11:31
  • @skaffman, @all, apologize, I didn't notice it. I corrected the situation now. Thank you for informing me that. – hephestos Feb 01 '11 at 18:26

1 Answers1

2

This is a much more general question of "composition vs inheritance", and is independent of Spring and Hibernate.

See this other answer for a full description/argument.

Briefly, while it's sometimes tempting to extend another class for convenience, you almost always end up regretting it later. Go the extra mile, compose your objects rather than extend them, and you'll win over the longer term.

Community
  • 1
  • 1
skaffman
  • 398,947
  • 96
  • 818
  • 769