Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Pattern »

Re: DAO relation with business object

Chad Woolley

2004-06-26


Wim,

Check out my thread in the archives of this list called "What is a Data Object?":

http://archives.java.sun.com/cgi-bin/wa?A1=ind0401&L=j2eepatterns-interest&D=0#14

In my opinion, when they upgraded the book for the second edition, they left
some subtle but big holes in explaining just what is a "Data Object", "Transfer
Object", "Value Object" (which is apparently replaced by Transfer Object but
still referenced in the second edition index), and "Business Object".

In addition to the thread (for which I never got a satisfactory answer), emails
to the authors got no response...

Also, it will be interesting to see how the "Core J2EE Patterns" evolve with the
apparent direction of the EJB spec towards supporting "Dependency Injection". I
would think that it would result in some major changes to these patterns :)

Good Luck,
Chad


"Deblauwe, Wim" <wim.deblauwe@(protected):
> Hi,
>
> I've looking at the DAO pattern lately and have some problems with it.
> Especially what is ment by Business Object and ValueObject?
>
> In my words I would call a class User that is a POJO a Business Object, and
> I would place it in a package "business".
>
> I would then have a class ValueUser in my data package that has all the same
> methods as business.User. In fact, business.User is just a delegate to
> data.ValueUser.
>
> Is this already correct? Or is the business class something else and is my
> User class already a ValueObject?
>
> 2nd problem:
> When I then create my DAO, e.g. UserDAO. This would typically reside in the
> data package. There are 2 options then:
>
> public User getUser(int id);
>
> or
>
> public ValueUser getUser(id);
>
> If my business.User class is already a ValueObject, then a class from my
> data-layer is dependant on a class from my business-layer. This would be
> undesirable I think.
> Otherwise we refer to the ValueUser which is in the same layer, so this
> seems ok. But when you try to unit-test User when it is just a delegate for
> ValueUser, you will do this:
>
> ValueUser valueUser = new ValueUser();
> valueUser.setName( "testName" );
> ... some more here
>
> User user = new User();
> user.setValueObject( valueUser );
>
> assertEquals( user.getName(), "testName" );
>
> And I really don't like this. You have to create 2 objects, where 1 should
> be enough.
>
>
> I hope the people on this list can help me find some answers,
>
> bye,
>
> Wim

====================================================================
Companion Site: http://www.corej2eepatterns.com
J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.