Let's say I create this interface :
interface Equipable
{
public bool Equip(Equipment equipment);
}
Let's just assume our Equipment class is empty for now:
class Equipment
{
}
I create a derived class from Equipment (let's keep it simple):
class Trinkets : Equipment
{
...
public Trinkets(...)
{
...
}
}
Then I want a Trinket class that implements Equipable and that uses its method:
class Trinket : Item, Equipable
{
bool Equipable.Equip(Trinkets trinkets)
{
return true;
}
}
But it seems I can't do this (CS0539), I can't use Trinkets class (which however is Equipment derived class) as a method parameter of my interface.
This didn't work for me and seems far-fetched: Implementation of interface when using child class of a parent class in method of interface. And it also seems that the above solution does not allow you to use other classes than the base class declared in the interface header.
So my question is simple, is there a way to do what I'm trying to do? Is it bad practice? If it is, what should I do to overcome this problem?