5 ms·
I've always thought inheritance is used to model is-a relationships. Sharing code may be a side effect, but it's certainly not the reason to use it. Using inhe
by jefffoster 13y ago
I've always thought inheritance is used to model is-a relationships. Sharing code may be a side effect, but it's certainly not the reason to use it.
Using inheritance to share code is usually better achieved by factoring that code out to a separate object and having the objects in a inheritance relationship use it by composition.
- justincormack 13y agoHmm, interesting view. But why would you want to model is-a relationships? Other than to share code?
- AndrewDucker 13y agoThink of it as enforced documentation. If I say that my object is a Customer then I know what can be done with it. If I have a method that says it takes a Customer object then the calling point knows what to pass in, and my method knows it can rely on that object satisfying certain conditions. Basically it removes (some of) the need to document separately, and it enforces that the documentation is adhered to.