When you have many classes, it is often necessary to get access to fields/methods of one class from the other one. I'm not very experienced with Java and I've recently found this method which seem to be very convenient (better than passing variables from one class to another):
class MyClass {
private static MyClass _instance = null;
public MyClass(){
...
}
public static getInstance(){
if (_instance == null) {
_instance = new MyClass();
}
return _instance;
}
}
Now in any other class I can simply do
MyClass.getInstance().callSomething()
However I do not see such way of accessing other classes in Java examples and tutorials that I find in the Internet. So that got me thinking, are there maybe some potential problems with such approach? Especially when you have many classes and hence many such static calls in each?