I would like to know if using singleton pattern for my databaseHelper.java class, which have all database related operations i.e (Crud) is a good idea or not? I want to minimize my database hit and memory usage. I use c3p0 i.e connection pooling.
Asked
Active
Viewed 999 times
1 Answers
2
Strictly speaking, this is an awful idea for too many reasons.
I suggest you run a simple google search, and even here to find out why. No point in spaming this site.
For example:
- Is it OK to have singleton DAO objects?
- https://stackoverflow.com/questions/6516230/is-it-ok-to-make-a-dao-class-as-singleton
- Singleton Design Pattern: Pitfalls
- Alternatives for the singleton pattern? (C# but you can get the idea)
Try looking at the solutions provided by the Spring framework. It would give you a much better starting point.

Community
- 1
- 1

Eran Harel
- 2,325
- 19
- 28