You need to maintain the same instance of the object to fit the Singleton pattern, so your approach makes sense: changing members.
However, if you want to clear it a bit, why not just have an internal list, for example:
ArrayList<Object> members = new ArrayList<Object>();
Another option would be to have a HashMap that associates a keyword with an element.
HashMap<String,Object> members = new HashMap<String,Object>();
For ArrayList or HashMap the clearAll method might look like this:
public class ModuleState() { public void clearAll() { members.clear(); } }
This method does not need to be changed.
source share