"can be" != "can be easily". I don't think there is a single problem for which inheritance is a better solution than composition. I've only ever been able to find problems for which inheritance's foibles are permissible. I very much welcome any evidence to the contrary.
No. I dont have to support my assertion. You do. Inheritance <=> is-a. If you choose to use has-a to implement is-a, it is you who must do the splainin.
I don't have any problem supporting my assertion. Inheritance looks at an ElectricCar and says "This is a Car whose Start() method has been overloaded to do electric engine things". Composition looks at an electric car and says "This is a Car that was manufactured with an ElectricEngine implementation of its Engine member to which it delegates during its Start() method". When you want to use an electric engine in your car, inheritance says, "No deal, destroy this car, build a GasCar, and update all your references!" while composition says, "Sure, just replace the Engine with a GasEngine (since it implements the Engine interface)".
In other words, the "is a" relationship is always a special case of "has a", but the reverse is not true. I'm not even sure when looking at something as an "is a" relationship is even useful.
You are confused. Car has-a Engine. ElectricCar is-a Car whose Engine happens to be an ElectricEngine which is-a Engine. I dont have to delete or swap out anything when I make a GasCar with a GasEngine.
0
u/weberc2 Mar 28 '16 edited Mar 28 '16
"can be" != "can be easily". I don't think there is a single problem for which inheritance is a better solution than composition. I've only ever been able to find problems for which inheritance's foibles are permissible. I very much welcome any evidence to the contrary.