0

In our application we have multiple layers.

  1. UI -> This can be JSP/ JSON result of the API
  2. Controllers -> as in MVC
  3. Services -> perform single business operation per service
  4. DAOs -> Data Access Layer (including connection/and DB layer)

And two types of ValueObjects

  1. FormValueObjects --> More close to View
  2. Entities --> replica of a row in DB

Since, Entities are DB related, they should not be exposed to other layers.

Since FormValueObjects are not related to DB, they should not be exposed to DAO layer.

I need to populate FormValueObjects from Entities and vice versa. In which layer should this be done? DAO layer/ Services layer or should I create an Adapter layer in between the two?

Please suggest me a good design.

2

That's the responsibility of your controller as that is the class that is responsible for receiving data from the view and translating it onto methods for the model, as well as receiving data from the model and handing it up to the view.

This does not mean the controller has to do this directly however. Your model can use ViewBuilders for example to build view-objects from Entities and these builders would probably belong to the view-layer. For changes to the model, the controller could just as well package data from the view into a command and hand that off to a command-handler type object. This might be part of the domain layer.

  • oh!! that gave me a completely different aspect. I was thinking that value objects would be used in most of the layers. but using entity for most of layers is something that I never thought of. I think I get your point here, It helps preventing malicious data provided by user to be filtered at first place itself too apart from other advantages. – Mohit Kanwar Aug 3 '15 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.