• 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?
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!