开发者

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 .

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜