What is the best way to share data between separate classes in Java? I have a bunch of variables that are used by different classes in separate files in different ways. Let
This question is a bit mad - the code in the question won't compile.
public class Main {
public static void main(String... args) {
MutableDataContainer m = new MutableDataContainer();
ImmutableDataContainer i = computeImmutableData();
new ADoer().doA(m, i);
new BDoer().doB(m, i);
}
...
}
class MutableDataContainer {
private int x, y;
... // getters and setters below
}
class ImmutableDataContainer {
private final int p, q, r, s;
... // getters below
}
You'll need to define ADoer
and BDoer
as well.