Implementing an interface I and extending a class B that implements interface J parent of I

77 Views Asked by At

I have an interface for an entity of a game IEntity such that

public interface IEntity {
    getATK();
    setATK();
    getDEF();
    setDEF();
}

So I can call game items commands constructors such as atkPotion(IEntity entity) without depending on any implementation (at least that's why I learned from SOLID DIP). However, I also have two common types of entities (with exclusive attributes), just like

public interface IPlayer extends IEntity {
    setEXP();
    getEXP();
}
    
public interface IMonster extends IEntity {
    setElement();
    getElement();
}

that are also interfaces in order to use expPotion(IPlayer), elementDungeon(IMonster) commands and not broke DIP.

The problem comes out when I want to make an implementation StdPlayer of IPlayer and another StdMonster of IMonster, but both approaches have the same behaviour for getATK(), setATK(), getDEF(), setDEF(). It is correct to make a general implementation StdEntity such that StdPlayer extends StdEntity and implements IPlayer, and StdMonster extends StdEntity and implements IMonster? Or there is a way better approach for this problem?

0

There are 0 best solutions below