http://yatur.livejournal.com/ ([identity profile] yatur.livejournal.com) wrote in [personal profile] juan_gandhi 2011-01-25 03:28 am (UTC)

I agree. Most of the time I use composition instead of imlpementation inheritance. Composition gives us better testability and control (e.g., two "super" objects can share the same "sub" object, which is impossible with inheritance).

Most inheritance attempts die when asked "can X have more than one Y". Can a car have more than one steering wheel? Well, yeah, why not. It would be a weird car, but it is quite possible. So, car is not a subclass of steering wheel.

There are, of course, other tests, but this one weeds off the vast majority of inheritance candidates.

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting