interface ITurtle
{
void Fight();
void EatPizza();
}
interface ILeonardo : ITurtle
{
void UseKatana();
}
interface IRaphael : ITurtle
{
void UseSai();
}
interface IDonatello : ITurtle
{
void UseBo();
}
interface IMichelangelo : ITurtle
{
void UseNunchuku();
}
What if I want to create a great turtle that can do all 4? I want the code:
class GrandTurtle : IMichelangelo, IDonatello, IRaphael, ILeonardo
{
// Implementation not shown for brevity.
}
Is this possible, because now I feel that I need to implement Fight()and EatPizza()4 times. But I think that these two common functions will be allowed and should only be performed once, right?
I could create 4 intermediate interfaces without inheritance ITurtleand then GrandTurtleimplement ITurtle. This solves the problem of interface inheritance, but now it looks semantically incorrect, because it makes it ITurtlelook like the fifth brother, who is not there. Also, I want to be able to create classes that are specific to turtles, for example class BostonLeonardo : ILeonardo.
- , " " , , , , , .