I am currently working on a web based application which requires database access in order to execute various sql statements.
I can take these approaches:
1) Create a stateless DAO, i.e everything is static.
Pros: I do not need to worry about thread safety / performance.
Cons: Difficult to switch between DAOs...but in my case I'm unlikely to need that anyway.
2) Create an interface for my DAO and instantiate an implementing DAO class.
Pros: The client is only exposed to the interface and therefore easy to switch DAOs.
Cons: Now I have to worry about thread safety. If I make my DAO a singleton and synchronized, it will affect performance since several clients will be using the same DAO.
After doing a fair amount of online research, the preference seems to be option 2. But I'm not quite sure why? What other cons does option 1 have?
Cheers,
Sid