  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | DAO relation with business object | DAO relation with business object 2004-06-21 - By Deblauwe, Wim
Back 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
Ing. Wim Deblauwe Software Development Engineer
BarcoView - Medical Imaging Systems Theodoor Sevenslaan 106 B-8500 Kortrijk, Belgium Tel. +32 56 233 985 Fax +32 56 233 457 www.barco.com <http://www.barco.com/> wim.deblauwe@(protected) <mailto:wim.deblauwe@(protected)>
- - - - - - - - DISCLAIMER - - - - - - - - Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.
==================================================================== 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)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859 (See http://iso-8859.ora-code.com)-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR></HEAD> <BODY> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>Hi,</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>I've looking at the DAO pattern lately and have some problems with it. Especially what is ment by Business Object and ValueObject?</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>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".</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>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.</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>Is this already correct? Or is the business class something else and is my User class already a ValueObject?</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>2nd problem:</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>When I then create my DAO, e.g. UserDAO. This would typically reside in the data package. There are 2 options then:</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>public User getUser(int id);</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>or</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>public ValueUser getUser(id);</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>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.</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>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:</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>ValueUser valueUser = new ValueUser();</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>valueUser.setName( "testName" );</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>... some more here</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>User user = new User();</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>user.setValueObject( valueUser );</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>assertEquals( user.getName(), "testName" );</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>And I really don't like this. You have to create 2 objects, where 1 should be enough.</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>I hope the people on this list can help me find some answers,</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>bye,</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2>Wim</FONT></SPAN></DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV><SPAN class=296160015-21062004><FONT face=Verdana size=2></FONT></SPAN> </DIV> <DIV class=Section1><FONT face=Arial size=2></FONT> <P><BR><SPAN style="FONT-FAMILY: Arial"> </SPAN> <BR><B><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana; mso-bidi-font-size: 7.5pt">Ing. Wim Deblauwe</SPAN></B><SPAN style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: Verdana; mso-bidi-font-size: 7 .5pt">Software Development Engineer</SPAN><SPAN style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt"> < /SPAN><SPAN style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana; mso-bidi-font-size: 7.5pt" >BarcoView - Medical Imaging Systems</SPAN><SPAN style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: Verdana; mso-bidi-font-size: 7 .5pt">Theodoor Sevenslaan 106</SPAN><SPAN style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: Verdana; mso-bidi-font-size: 7 .5pt">B-8500 Kortrijk, Belgium</SPAN><SPAN style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: Verdana; mso-bidi-font-size: 7 .5pt">Tel. +32 56 233 985 Fax +32 56 233 457</SPAN><SPAN style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"> <BR></SPAN><U><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: Verdana; mso-bidi-font-size: 7 .5pt"><A href="http://www.barco.com/">www.barco.com</A></SPAN></U><SPAN style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"> <BR></SPAN><U><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: Verdana; mso-bidi-font-size: 7 .5pt"><A href="mailto:wim.deblauwe@(protected)">wim.deblauwe@(protected)</A></SPAN></U></P>< /DIV> <DIV> </DIV></BODY></HTML>
<P><I><FONT SIZE=2 FACE="Arial">- - - - - - - - DISCLAIMER - - - - - - - - < /FONT></I></P>
<P><I><FONT SIZE=2 FACE="Arial">Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.</FONT></I></P> ==================================================================== 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)
|
|
 |