So I have a class that looks something like this:
public abstract class GameObject {
public abstract boolean hasValidLocation();
//some more code that will use hasValidLocation
}
and an interface:
public interface Collidable {
//some abstract references to functions of the game object
default boolean hasValidLocation() {
//checks whether or not the the game object has a valid locaton
}
}
and I have a similar interface for NotCollidable
and would like to implement the abstract function hasValidLocation
from the game object with this interface:
public class GameObject1 extends GameObject implements Collidable {
//some code
}
but java says that GameObject1
does not implement hasValidLocation
. I can't use 2 abstract classes since I already split gameObject
in a DynamicGameObject
and StaticGameObject
and those can both be collidable and not collidable.
Is there something I did wrong or an alternative solution that doesn't require me to write hasValidLocation()
multiple times?