I have a class that represents a basic page with "go back", "go forward", and "canel" buttons in Wicket. But not all pages have all the buttons, e. g. the first page doesn't have "go back" obviously.
My idea is to define a generic ActionHandler
public interface ActionHandler {
void perform();
}
and let subclasses return the actions they support:
public Derived extends BasicPage {
protected ActionHandler getForwardHandler() {
return new ActionHandler() {
void perform() {
doIt();
}
};
}
}
The question is: why not to use protected fields?
public Derived extends BasicPage {
protected forwardHandler = new ActionHandler() {
void perform() {
doIt();
}
};
}
Another option would be not to use inheritance (which doesn't make really sense here) and set the ActionHandlers from the outside:
Toolbar toolbar = new Toolbar();
toolbar.setForwardHandler(new ActionHandler() {
void perform() {
doIt();
}
});
The reason why I'm not using interfaces like ForwardHandler, and CancelHandler is, that I want to pass the handler to a toolbar, what takes ActionHandlers as parameters. Or would you pass the entire page to the toolbar and let the toolbar decide what buttons to display depending on the implemented interfaces? Sounds like bad OOP to me.
The idea is that not every page has to define a new toolbar, but maybe it would be simpler ...