Java Mailing List Archive

http://www.junlu.com/

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

Re: DAO - Static Methods

R Riluvan

2004-12-21

Replies:

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: Delivery-Date: Tue, 21 Dec 2004 22:11:50 -0500 Received: from swjscmail2.Sun.COM[192.18.99.108] (helo=swjscmail2.java.sun.com) by mx.perfora.net with ESMTP (Nemesis), id 0MKv22-1Cgwuj2fAz-0007wj; Tue, 21 Dec 2004 22:11:49 -0500 Received: from swjscmail1 (swjscmail1.Sun.COM [192.18.99.107]) by swjscmail2.java.sun.com (Postfix) with ESMTP id 7C414211FB; Tue, 21 Dec 2004 20:04:15 -0700 (MST) Received: from JAVA.SUN.COM by JAVA.SUN.COM (LISTSERV-TCP/IP release 1.8e) with spool id 51069329 for J2EEPATTERNS-INTEREST@JAVA.SUN.COM; Tue, 21 Dec 2004 19:58:57 -0700 X-Original-To: J2EEPATTERNS-INTEREST@JAVA.SUN.COM Delivered-To: J2EEPATTERNS-INTEREST@JAVA.SUN.COM Received: from swjscmail2.java.sun.com (swjscmail2.Sun.COM [192.18.99.108]) by swjscmail1.java.sun.com (Postfix) with ESMTP id ADD804AE6 for ; Tue, 21 Dec 2004 19:58:57 -0700 (MST) Received: from swjscmail1 (swjscmail1.Sun.COM [192.18.99.107]) by swjscmail2.java.sun.com (Postfix) with ESMTP id 79768211C0; Tue, 21 Dec 2004 20:04:00 -0700 (MST) Message-ID: Date: Tue, 21 Dec 2004 19:58:44 -0700 Reply-To: An interest list for Sun Java Center J2EE Pattern Catalog Sender: An interest list for Sun Java Center J2EE Pattern Catalog From: Marvin Toll Subject: Re: DAO - Static Methods Comments: To: YourFirstName YourLastName STOP MORE SPAM To: J2EEPATTERNS-INTEREST@JAVA.SUN.COM Precedence: list Envelope-To: java@JUNLU.COM X-SpamScore: 0.000 I'm struggling a bit to understand the key points of the attached response. 1. What advantage does a factory add? For example, there is no need for DAO factory caching capability for objects that can not be instantiated. 2. In an O/R Persistence application mentioned, the DAO's would not be reusable for a JDBC or EJB application - in this case, they invoke methods specific to the Toplink API. So the issue of a "DAO deciding how database calls are made" should not be applicable. Right? 3. How do static methods "restrict the usage"? Static methods should be as accessible as an instance method. Right? A further point - in the application mentioned the DAOs are very light- weight. Typically, all four standard CRUD operations can be performed with ten (or less) unique lines of code. Any elaboration on these notions? _Marvin -----Original Message----- On Tue, 21 Dec 2004 15:15:12 -0500, R Riluvan wrote: 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----- From: Marvin Toll [mailto:MarvinToll@GTCGROUP.COM] Sent: Saturday, December 18, 2004 3:15 PM To: J2EEPATTERNS-INTEREST@JAVA.SUN.COM Cc: Marvin Toll Subject: DAO - Static Methods 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
©2008 junlu.com - Jax Systems, LLC, U.S.A.