I am making a button class that handles input and drawing on its own; the only thing that needs to be determined is the location and what happens when the button is pressed.
In this situation, would it be better to have an interface ButtonPressListener
and have it as a parameter in the constructor Button
, or if to Button
be abstract with an abstract method pressed()
?
The resulting initiation code for Button
will look like this:
new Button(x,y,new ButtonPressListener(){
@Override
protected void pressed(){
}
});
or
new Button(x,y){
@Override
protected void pressed(){
}
};
Also, in other similar situations, what should be considered when choosing between two approaches?
Thanks.
source
share