I am just practicing some random coding principles mostly the Liskov Substitution Principle from the SOLID principles...
Anyway I was experimenting with random scenarios to help deepen my understanding and I ran into an issue that will make more sense after viewing the following code.
In a class I've called Item
:
public virtual bool CheckIfMeetStats(IHasStats hasStats)
{
if (_hasStatRequirement)
{
if (hasStats.Strength >= _strengthRequirement && hasStats.Level >= _levelRequirement)
{
return true;
}
else
{
return false;
}
}
else
{
return true;
}
}
Which requires an IHasStats
as an argument, then in a class that inherits from Item when I try to override it I try to pass an interface as an argument that inherits from IHasStats
:
public interface IHaveMagic : IHasStats
{
public int CosmicPower { get; set; }
public int Mana { get; set; }
}
Into EDIT: (To make it more clear I have put the parameters I'm trying to pass here, originally I kept it to what works):
public override bool CheckIfMeetStats(IHaveMagic haveMagic)
{
return base.CheckIfMeetStats(haveMagic);
}
If I try to pass IHaveMagic
as an argument it doesn't work it says suitable method not found. I don't understand why because of it being a descendent of IHasStats
.
Can someone please explain why and recommend what they would do to still follow SOLID principles and be able to check if a character meets the stats requirements for an item.
I'm still getting used to Stack overflow whoever edited and closed my question because they said its similar to a different post please describe why because I don't see how it answers my question or at the very least its VERY confusing and unclear...