I asked a question about how to structure an interface given that an object can be used in more than one way. The answer given was fine, but it didn't really address my primary problem. I decided to try for myself, and then come back with a more clear example/question.
Take for example this Character interface:
public interface Character {
void attack(Weapon toAttackwith, Character enemy);
void reload(Reloadable reload, Replenishitem replenish);
}
public interface Weapon {
void attack();
}
public interface Reloadable {
void replenish();
}
and Implementation:
public final class ReloadableWeapon implements GameItem, Reloadable, Weapon {
@Override
public void attack() {}
@Override
public void replenish() {}
}
A game weapon can be used to attack an Enemy, however, not all Weapons are reloadable. So in my character interface
and created a method called reload with certain parameters
. Reload doesn't necessarily just mean weapons, potion bottles/containers can be reloaded (refilled, two different words for the same behavior).
Is adding the reload method in the character interface
considered code smell?