开发者

Singleton pattern for database.

开发者 https://www.devze.com 2023-03-23 19:13 出处:网络
I would like to know if using singleton pattern for my databaseHelper.java class, which have all databa开发者_开发问答se related operations i.e (Crud) is a good idea or not? I want to minimize my data

I would like to know if using singleton pattern for my databaseHelper.java class, which have all databa开发者_开发问答se 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消