I use helper classes in my code. They are for example, displayHelper ( to open screens ) , resourceHelper (to get text resources) etc. I would like to not instantiate an instance every time. For that I created a common object which every class will extend
public class CommonObject {
protected PropertiesManager properties = new PropertiesManager();
protected DisplayHelper displayHelper = new DisplayHelper();
}
A class will do this
public class AbcController extends CommonObject
and in that class I can just use
displayHelper.openScreen(new AbcScreen());
this seems to work although I dont think this is the best way to do it. More over, I can't use this common object for classes which extend other classes.
What is the best practice to share common code across classes?
PS: I dont like using static or singletons because of the issues created which hinders proper unit testing. Dont want to use singletons because it holds state.
the solution has to work for Java 1.3 as I code mainly for blackberry