In Java, there is no global access like in C++. So what would one do if they wanted to create a container of objects that can be accessed from any class? Or say a java bean that holds global values.
For example, if I am making an elevator simulator, fields that need to be known by all like int numElevators
have to be place somewhere right? Same with the collection object for elevators Elevators[] elevators
.
I can think of one way which is to create a singleton class to store all those global variables. Then use static methods to provide access from any class. But is there a more elegant solution?