I was suggested to put my question here, so I'm doing so ;)
I need a common interface which represents some specific behavior:
public interface Contract(){
public void methodA();
public void methodB();
// and so on...
}
The problem is, that in order to fulfill this behavior, implementation can be totally stateless - it can have a private constructor and expose only static methods:
public class MyUtilityClass /*implements Contract*/{
private MyUtilityClass(){}
public static void methodA(){
// some implementation here...
}
public static void methodB(){
// some implementation here...
}
}
I have many such classes, with different behavior, so I want to refactor them and handle under a common interface.
Because I cannot implement Contract
by means of static methods, is the only solution to convert MyUtilityClass
to a singleton which implements the interface in order to achieve my goal? Or maybe would you suggest something else? For example Template method and Strategy which can by injected depending on a specific situation?
What would you propose?