I would like to ask about best-practice how to hold and change a global state of application. I have a Parser (which now is a singleton) which among others have properties like
private String mode
private List<String> loadedResources
Then I have about ten modules with a very simple interface
ModuleOutput parse(String line, Path context) throws ModuleException;
Some modules do need to (some modules do not) get or set mode of the already processed file.
if (Parser.getInstance().getMode().equals("something") { ... }
or
Parser.getInstance().setMode("something");
which changes a state of the application and parser itself and other modules work with it.
Two modules (of ten) also want to add to loadedResources
if (!Parser.getInstance().getLoadedResources().contains(resource)) {
Parser.getInstance().getLoadedResources().add(resource);
} else {
// resource already loaded ...
}
but others not.
I do not like storing the global data in singleton and have modules reaching for it (because of tests and so on) but I do not even like that I would need to send all eventually needed information to modules which can process them... and then create big objects to return which would tell the Parser how to change the state (as well as the "globally needed" data can change over time), however it would probably be much cleaner. What are your suggestions? Thanks in advance.