Results 1 to 3 of 3

Thread: Domain Object, Action and DAO defined in the sample Petstore

  1. #1
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    29

    Default Domain Object, Action and DAO defined in the sample Petstore

    Hi,
    A question regarding to the Petstore example included in the Springframework distribution package (Struts implementation):

    1. Is it a common practice to use Domain Object (like Order, Product) directly in Action and ActionForm ? I read somewhere talking about DTO/Value Object. So what's the pros and cons of using Domain Object directly in Web tier ?

    I was having the impression that web tier should only handle Strings (may be plus Boolean). However, the Petstore actually stores Order directly in the ActionForm and let JSP access the non-string properties directly:
    In ViewOrder.jsp, we have:

    <c:out value="${order.orderId}"/>

    orderId is an integer.

    I thought we should use BeanUtils to do some data conversion.

    thanks
    lixin

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    In general, if you can do without a DTO layer (read duplication, loss of OO) you should. The idea of string-only data in the web tier is a commonplace hack due to the fact that Struts enforces concrete inheritance from ActionFrom (meaning that you need a separate form object and can't populate a domain object). The fact that Spring MVC lets you populate true domain objects is A Good Thing.

    DTOs should only be used if you need to transfer objects across a remote boundary. In most web applications you don't need to, and shouldn't.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    Quote Originally Posted by Rod Johnson

    DTOs should only be used if you need to transfer objects across a remote boundary. In most web applications you don't need to, and shouldn't.
    I would add to this that even for remote boundaries, there is in many cases nothing stopping you from using your domain objects as DTOs, although when dealing with other apps it may make sense to define a simpler set of objects used just for the remote interface...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •