Announcement Announcement Module
No announcement yet.
Binding to business domain objects Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding to business domain objects

    Is it ever a good idea to bind directly to business domain objects?

    My answer so far: NO, except for trivial cases where you have a domain object with no associations to other domain objects, so a domain object with just value (Strings, ...) properties.

    With the bad rep that DTOs have gotten lately (and I agree, they are not true objects!) I was doing my best to bind directly to the domain objects in a Spring/Hibernate web app. However, I kept running into all kinds of problems (e.g. side effects because of business logic in setters during data binding...), most of which can be solved by binding to dummy DTOs and having your business facades process those DTOs and invoke the required domain object methods.

    Am I missing something here or are DTOs just a necessary evil?


  • #2
    We bind to domain objects whenever we can to save time/effort.

    This is pretty subjective, but if you're building a page where most of the domain object fields appear on that page, there's nothing to gain by building an intermediate DTO type object.

    You can also of course plug in property editors to easily handle non-String properties.

    Some purists might disagree, but practically speaking, who cares. i.e. DTOs are just evil, not a necessary evil.


    • #3
      Ofcourse I'm not saying that you should have DTO in all cases, especially when you're just displaying data. In that case there are no issues with just pulling the data directly out of the domain objects.

      We bind to domain objects whenever we can to save time/effort.
      I agree, there are cases where it will work. But it seems to brake down in most non-trivial cases when your setters have complex logic in them, especially with bidirectional association between domain objects.

      As you say, for simple unidirectional associations you might also be able to cope by just registering the required property editor.

      Here is a very interesting discussion that also mentions these kinds of issues, some of which also relate to the open-session-in-view pattern: