How to model and handle presentation DTO's to abstract from complicated domain model?

Posted by arrages on Stack Overflow See other posts from Stack Overflow or by arrages
Published on 2010-04-11T20:36:04Z Indexed on 2010/04/11 20:43 UTC
Read the original article Hit count: 197

Hi I am developing an application that needs to work with a complex domain model using Hibernate. This application uses Spring MVC and using the domain objects in the presentation layer is very messy so I think I should use DTO's that go to and from my service layer so that these match what I need in my views. Now lets assume I have a CarLease entity whose properties are not simple java primitives but it's composed with other entities like Make, Model, etc

    public class CarLease {
        private Make make;
        Private Model model;
        .
        .
        .
    }

most properties are in this fashion and they are selectable using drop down selects on the jsp view, each will post back an ID to the controller.

Now considering some standard use cases: create, edit, display

How would you go about modeling the presentation DTO's to be used as form backing objects and communication between presentation and service layers??

Would you create a different DTO for each case (create, edit, display), would you make DTO's for the complex attributes? if so where would you translate the ID to entity?

how and where would you handle validation, DTO/Domain assembly, what would you return from service layer methods? (create, edit, get)

As you can see, I now I will benefit by separating my view from the domain objects (very complex with lots of stuff I don't need.) but I am having a hard time finding any real world examples and best practices for this. I need some architecture guidance from top to bottom, please keep in mind I will use Spring MVC in case that may leverage on your anwser.

thanks in advance.

© Stack Overflow or respective owner

Related posts about java

Related posts about spring-mvc