File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Is it ok to make a DAO class as Singleton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Is it ok to make a DAO class as Singleton" Watch "Is it ok to make a DAO class as Singleton" New topic
Author

Is it ok to make a DAO class as Singleton

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Assume that we have methods such as insert , update , select and delete inside my DAO class . So please tell me if i make this DAO class as Singleton .

In my opinion this saves a ot of memory .please guide

Save India From Corruption - Anna Hazare.
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Well, no. Since Singletons are EVIL! ;)

Actually, using the DAOFactory-pattern is better. It allows you to control your DAO-objects in a way that makes it easy to switch the underlying DS and/or use a persistence framework.

Example on how to do: http://www.ibm.com/developerworks/library/j-dao/

Addition: Also, it makes testing and mocking a lot easier.
Arnold Reuser
Ranch Hand

Joined: Nov 20, 2003
Posts: 194
In my opinion this saves a ot of memory .please guide


If your using an EJB centric architecture use stateless sesion beans for this purpose.
Stateless session beans are pooled and therefore memory consumption is managed by the container.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it ok to make a DAO class as Singleton
 
Similar Threads
Using a Singleton for a DAO class
DAOFactory Classes in Sequence / Component ?
Is it Okay if a DAO class is made as Singleton
When to use Singleton Pattern