This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which One is a Good Design?

 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

Suppose I have a Hibernate entity like this.


And I have simple architecture like this (for simplicity, I've removed all the interfaces, etc)
View Layer -> Service Layer -> DAO Layer

This is my DAO layer code.


This is my service layer code.

Option 1


Option 2


The view layer will eventually invoke the server layer, e.g. the UserPage will call the UserService class.

My question is, which one is a better design, option 1 (to pass a Hibernate entity to a view layer) or option 2 (to create another POJO that gets all the information from the Hibernate entity and pass it to a view layer)?

In my opinion, option 2 violates the DRY principle since we need to create another POJO which is basically just a subset of the Hibernate entity, but option 1 seems to expose too much information to the view layer, i.e. the database specific properties, e.g. id, createdBy, lastModifiedBy, createdBy, createdDate.

What do you guys think?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic