So I am making a game in LWJGL 2 and my project has 4 classes (Entity,AliveEntity,Player,Tree). I want my entities(e.g. trees, ferns,some items) to extend Entity class and player to extend Entity and AliveEntity at the same time so player can have hp, velocity, equipment, etc. So it looks like this now:
public class Entity{
public Entity(){ }
public void methodForEveryEntity(){ }
}
public class AliveEntity extends Entity{
public AliveEntity(){ super(); }
public void methodForOnlyLivingEntities(){ }
}
public class Player extends AliveEntity{
public Player(){ super(); }
//it can use methods from AliveEntity and Entity classes
}
public class Tree extends Entity{
public Tree(){ super(); }
//only methods from Entity class
}
Is my approach is correct? If no, then can you tell me what is the best way of doing this? I thought about Interfaces but I am not a big fan of them...
To my knowledge this seem to be correct when extending. When ever I need to I like to think of it in the manner of hierarchy. Does the extending follow it? Both Tree and AliveEntity are part of Entity, and Player is a part of AliveEntity though not part of Tree hence it only extends to AliveEntity . Hope this helps.