I have some database functions and would like to make those database functions a开发者_开发百科ccessible too all of my other classes. I would like to keep the functions in one place so they are easy to modify. What is the best way to achieve this goal? My application is running on android and is using threading and events.
Thanks in advance, if you need more information let me know.
- make a class with all static methods/variables, or alternatively a Singleton
- synchronize stuff if you need to, sounds like you might
Absolutely no reason why you can't have a package level class called something like DatabaseUtils
and put general static methods in there. Doesn't have much bearing on it that you're using threading and events, although you will want to ensure your utility methods can handle simultaneous access if that's a possibility.
精彩评论