• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

design question

 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Our product is a complex is a set of "sub-product".

My " sub -product " is the center of the product and responsible for catalog management.

Me and my work colleagues has an discussion if we should expose the hibernate model in the service layer or should we expose an interface in order to abstract the database structre.

The disadvantage in expose interface is the performance, complexity and etc .

What do you thinks?
 
Javid Jamae
Author
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're talking about a service layer that acts as an interface to external systems, you definitely don't want to expose your hibernate model. If you read through Martin Fowler's Patterns of Enterprise Application Architecture, he has a good discussion as to why you don't want to do this.

Primarily:
- You don't want to expose transactions to your client (avoid distributed transactions)
- You want your service layer to be coarse grained to avoid performance issues with distributed calls (no, this is not premature optimization, it is architecture)
- You want to eliminate duplication in code that the clients would have by stringing together find-grained data access calls.

 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not external system.

My sub-product is responsible for manage the item catalog.
All other sub-products depend on the item catalog data, so i need to give them a service layer for getting data from the catalog.

Most of the " get data " are for bulk of entities.

The result of the service layer can be the same pojo of the hibernate or interface.

Disadvantage of expose the hibernate model:
1. you lost encapculation.
2. you expose the database structre
3. bad for refactor

Advantage of hibernate:
1. its easly to expose service layer for get, because they can use hibernate criteria for fetching.
2. easly for performance
3. no need to write complex adapter.
3.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic