Announcement Announcement Module
Collapse
No announcement yet.
Domain Object, Action and DAO defined in the sample Petstore Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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.

    Comment


    • #3
      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...

      Comment

      Working...
      X