This is somewhat of a follow-up question to this question.
Suppose I have an inheritance tree as follows:
Car -> Ford -> Mustang -> MustangGT
Is there a benefit to defining interfaces for each of these classes? Example:
ICar -> IFord -> IMustang -> IMustangGT
I can see that maybe other classes (like Chevy
) would want to implement Icar
or IFord
and maybe even IMustang
, but probably not IMustangGT
because it is so specific. Are the interfaces superfluous in this case?
Also, I would think that any class that would want to implement IFord
would definitely want to use its one inheritance by inheriting from Ford
so as not to duplicate code. If that is a given, what is the benefit of also implementing IFord
?
I woudl create the first two levels, ICar and IFord and leave the second level alone until I need an interface at that second level.
Make an ICar and all the rest (Make=Ford, Model=Mustang, and stuff) as members of a class that implements the interface.
You might wanna have your Ford class and for example GM class and both implement ICar in order to use polymorphism if you don't wanna go down the route of checking
Make == Whatever
, that's up to your style.Anyway - In my opinion those are attributes of a car not the other way around - you just need one interface because methods are common: Brake, SpeedUp, etc.
Can a Ford do stuff that other cars cannot? I don't think so.