It would be better to have DAO as a private static member variable in a factory instead of having static methods in DAO. DAO could decide how database calls are made, but DAO cannot restrict how it is being invoked. Having static method in a DAO restricts the usage of such method calls accross the application.
----Original Message Follows----
From: Jayaraman Dorai <Jayaraman.Dorai@TRANSPLACE.COM>
Reply-To: An interest list for Sun Java Center J2EE Pattern Catalog <J2EEPATTERNS-INTEREST@JAVA.SUN.COM>
To: J2EEPATTERNS-INTEREST@JAVA.SUN.COM
Subject: Re: DAO - Static Methods
Date: Mon, 20 Dec 2004 16:07:44 -0600
MIME-Version: 1.0
Received: from swjscmail2.java.sun.com ([192.18.99.108]) by mc2-f21.hotmail.com with Microsoft SMTPSVC(6.0.3790.211); Mon, 20 Dec 2004 14:10:15 -0800
Received: from swjscmail1 (swjscmail1.Sun.COM [192.18.99.107])by swjscmail2.java.sun.com (Postfix) with ESMTPid 180312172F; Mon, 20 Dec 2004 15:02:52 -0700 (MST)
Received: from JAVA.SUN.COM by JAVA.SUN.COM (LISTSERV-TCP/IP release 1.8e) with spool id 50879984 for J2EEPATTERNS-INTEREST@JAVA.SUN.COM; Mon, 20 Dec 2004 14:57:36 -0700
Received: from psplotp1.transplace.com (unknown [65.64.216.68]) by swjscmail1.java.sun.com (Postfix) with ESMTP id BD8314833 for <J2EEPATTERNS-INTEREST@JAVA.SUN.COM>; Mon, 20 Dec 2004 14:57:35 -0700 (MST)
X-Message-Info: nNbrIwMvXSSVQVNuMHW65jovxNbCHsDzV8RK4fnrXis=
X-Original-To: J2EEPATTERNS-INTEREST@JAVA.SUN.COM
Delivered-To: J2EEPATTERNS-INTEREST@JAVA.SUN.COM
X-Mailer: Lotus Notes Release 5.0.8 June 18, 2001
X-MIMETrack: Serialize by Router on psplotp1/com(Release 5.0.11 |July 24, 2002) at 12/20/2004 04:10:08 PM
Precedence: list
Return-Path: owner-j2eepatterns-interest@JAVA.SUN.COM
X-OriginalArrivalTime: 20 Dec 2004 22:10:15.0797 (UTC) FILETIME=[AF199A50:01C4E6E0]
Have read somewhere on the net, but couldn't google it again, that static
classes are for utility methods and should not be used for executing
business operations. Using static methods makes the code procedural and is
not object oriented.
Technically, static DAO methods would work though.
Jayaraman
Marvin Toll
<MarvinToll@GTCGROUP.COM> To: J2EEPATTERNS-INTEREST@JAVA.SUN.COM
Sent by: An interest list cc:
for Sun Java Center J2EE Subject: DAO - Static Methods
Pattern Catalog
<J2EEPATTERNS-INTEREST@JA
VA.SUN.COM>
12/18/2004 02:14 PM
Please respond to An
interest list for Sun
Java Center J2EE Pattern
Catalog
Having recently participated on my first production implementation using
O/R Persistence (Toplink) - the team had an interesting design for DAOs.
A base abstract DAO class contained convenience methods and sub-classed
DAOs contained only static methods (with a private constructor). No DAO
Factory was required. Unit testing was conducted on the Application
Service objects - enabling Mock substitution of Business Objects as
needed. Both connection and transaction management were handled within
the Application Service objects and these resources were passed to the
DAOs as arguments.
What is interesting - is that the design decision for using static methods
was to promote/reinforce consistent use of stateless DAOs. In addition,
because the sub-classed DAOs were not instances - in effect, the Base DAO
static methods could be "overridden" by the sub-classed DAOs.
This is a different assertion for using static methods in DAOs then I've
previously encountered - and it worked very effectively for the team.
Any reaction to the notion of using static methods as a
convention/strategy for keeping state out of DAOs???
_Marvin
====================================================================
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@java.sun.com
====================================================================
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@java.sun.com
====================================================================
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@java.sun.com
From owner-j2eepatterns-interest@JAVA.SUN.COM Tue, 21 Dec 2004 21:58:44
Return-Path: