Value Objects and Domain Objects


General J2EE: Value Objects and Domain Objects

  1. Value Objects and Domain Objects (1 messages)


    Could somebody please explain to me the difference between Value Objects and Domain Objects, or are they the same?

    My understanding is that Value Objects are just used to transfer data, and that the Domain Objects have the business methods.

    Is this correct, or is it OK to have business logic in the Value Objects?

    Should I be getting my Value Object from my DataAccessObject and then use these to populate my Domain Objects before then calling the business methods on Domain Objects?

    If I'm using Hibernate or OJB should I get the persistence framework to return me Value Objects or Domain Objects?

    If this is the right way to go, can anybody point me in the right direction for a Struts example app that uses Value Objects, Domain Objects and some persistence technology like Hibernate or OJB.

    So many questions.

    Please help,

     - Martin Smith
  2. Value Objects and Domain Objects[ Go to top ]

    We are buttoning up a fairly large project and we used a single domain object layer in combination with our DAO -- which I regret.

    Some of the issues we ran into is that domain objects have conversational state, while the Value Objects (DTO's) represent the state of the database. Things can become very clean cut.

    DTO's, since they only have state, you make rules in the domain layer to only pass DTO's by copy. They also would have equals, hash, etc overridden in them-- as if they belonged in "java.lang.*"

    OrderSession.setData(OrderData data)
    { = (OrderData) data.clone();

       return (OrderData);

    The other thing is that the DTO's have getter's and setter's while the Domain Objects might only have getter's to help preserve it's internal state.

    Overall, I think seperating business state and business rules are the way to go. It will also help keep your Hibernate/OJB config/code cleaner when business logic gets really hairy.