简体   繁体   English

可以从所有其他类访问的类

[英]class accessible from all other classes

I have some database functions and would like to make those database functions accessible 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. 我的应用程序在android上运行,并且正在使用线程和事件。

Thanks in advance, if you need more information let me know. 在此先感谢,如果您需要更多信息,请告诉我们。

  • make a class with all static methods/variables, or alternatively a Singleton 使用所有静态方法/变量创建一个类,或者使用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. 绝对没有理由你不能拥有像DatabaseUtils这样的包级别类,并将常规静态方法放在那里。 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. 虽然您可能希望确保您的实用程序方法可以同时访问(如果可能),但您对使用线程和事件没有多大影响。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅具有一个实例的类,该实例可从所有其他类访问 - Class with only one instance that is accessible from all other classes 如何通过主类中的实例化使数组可访问? 可访问同一班级的所有班级 - How to make an Array Accessible from instantiation in main class? Accessible to all classes in same class 如何创建可以保留在内存中并可供所有其他类访问的类的对象? - How can I create an object of a class that can remain in memory and be accessible to all other classes? 使数据成员可从所有类访问 - Make data member accessible from all classes 其他包中的派生类无法访问受保护的嵌套类 - Protected nested class not accessible to derived classes in other package Android将偏好设置私下保存到我的应用中,但可以从所有类别访问 - Android saving preferences privately to my app but accessible from all classes 无法从 .java 类访问带有参数的 @Immutable 类的构造函数 - Constructor of @Immutable class with parameters is not accessible from .java classes 将一个类的属性/字段与(所有)其他类进行比较 - Compare property/field of a class with (all) other classes 如果一个类依赖于另一个包中的一个类,那么它是否依赖于该包中的所有其他类? - If a class depends on a class from another package, does it depend on all other classes in that package? 有没有一种方法可以将对象从主类更新为程序中的所有其他类? - Is there a way to update an object from the main class to all the other classes within the program?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM