开发者

Spring Beans and Hibernate tables

开发者 https://www.devze.com 2023-02-07 01:01 出处:网络
I have made an app and I experimented in two scenarios. Make a bean extend a Hibernate db object, or make the bean c开发者_Go百科lear distinct from db object.

I have made an app and I experimented in two scenarios. Make a bean extend a Hibernate db object, or make the bean c开发者_Go百科lear 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 ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消