Should I make my database adaptor class a singleton?
I am using the database adaptor from devx.com
I was wondering if I should make it a singleton so I can 开发者_开发技巧easily use it from a number of different classes without having to worry about multiple instances?
Though your logic is valid, I dont think you should. Think of concurrencies, eg. class X is updating the database, and class Y is retreiving values from it at the same time . So you have 2 operations on the database at the same time; having a singleton shall prevent this, as the db connection needs to be closed/reopened .
精彩评论