Review the following model:
interface Context {
BeanFactory getBeanFactory(); // public method
void refresh(); // public method
void destroy(); // public method
}
interface BeanFactory {
<T> T getBean(String id); // public method
void destroyBeans(); // should be private method for user, but visible for Context
}
class ContextImpl implements Context {
private BeanFactory beanFactory;
@Override
public void destroy() {
beanFactory.destroyBeans();
}
}
ContextImpl
uses BeanFactory
interface, that's why method destroyBeans()
is placed there. But I don't want it to be there, because it is internal API and should be hidden from user.
I thought of using AbstractBeanFactory
reference with protected destroyBeans()
method inside Context
. That will solve the problem of exposing method to end user, but will replace the interface with abstract class.
Another variant is to make another interface, that will extend end-user interface, and use it inside Context. This will break the ability for user to create his own BeanFactory implentations.
I wanted to know if there is a well-known solution for the problem or just see another alternatives.