I have an interface like so
public interface Manager {
public void manage();
}
Now, all Manager
s will need to load work to manage, however, I have mixed feelings about adding public void loadWork()
to the interface...
On one hand, all Manager
s will do this, but on the other hand, users of a Manager
class will not need to know about loadWork()
.
Question: Is it bad practice to add "helper" or "setup" type methods to an interface?
It's not always a bad idea to add "setup" methods in an interface. For example, Java EE has an interface called ServletContextListener that is purely meant to make setup and shut down. It's even sometimes acceptable to make interfaces with methods you should actually never directly call such as the Runnable or the Callable interface.
Being said that, it seems is that you want to force your developers to implement a loadWork() method in Manager but you also want to hide it from the class' users. As you say, one option is adding the method in the interface but this way the method will be accessible (which you don't want). If you don't want the method to have visibility I see two options:
At the end it comes to a balance between overengineering and good design. It's up to you to take the decision following the specific needs. Nevertheless, there is no 'perfect solution'.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments