so, day off before travel before onsite, playing ONI, having fun, but i want to muse about a highly geeky matter anyway…
do you ever override in a sub-class a method that’s already implemented in a super-class? i want to recommend to you a policy of avoiding that like the plague, whenever you can.
i will go further: i avoid, maybe not as much as the plague, but surely as much as the measles, even deriving any sub-class off of any super that has any implementations at all. (anything not a “pure virtual base class” in c++, “interface” in java. in languages that have no such concept, any super-class that has an implementation other than “throw new ForgotToOverride”.)
i came to this philosophy very slowly over an embarrassingly large number of years. i say “embarrassingly” because, nearly as soon as i came to it, it made itself clear almost immediately how much better/stronger/faster/kinder my resulting designs are. i came up through the OO revolution, you see, and i’m a confident and capable OO geek, surrounded by this thing, i’ll call it “implementation inheritance”. it was the air i breathed.
when i started TDD, i had an enormous amount to learn just in first the basics and then the intermediates. it took some time. as it progressed, i learned about a kind of meta-pattern i’d been engaging in for years & years. it’s a hard one to see, this meta-pattern, and that’s what took me so damned long. it’s trading the major value of getting what i’ve elsewhere called “rigorous” results for a variety of lesser values that essentially amounted to local convenience.
or, maybe, that’s not quite right.
let’s try another take: i was trading to get a kind of local appearance of convenience, and in so doing giving up an actual global improvement in my ability to ship more value faster.
and the worst part of it was, i wasn’t even getting that much local feeling of convenience. just a little. and i was giving up a lot of global value-shipping speed. and this wasn’t just one feature of my coding technique, i was doing it all over the place in myriad ways. TDD slowly helped me find those ways and choke them down, one by one. i will never not think of it fondly for doing that. one of the things i was doing, tho, was being what i thought was a facile and even gifted – i get perky at times – object-oriented programmer. i used implementation inheritance heavily.
the benefit of implementation inheritance is dreadfully obvious: it’s the fastest possible way in a statically typed language to re-use code you or someone else already wrote. and if you’re good at it, i was, you could carry it around with you all over the place, like an overloaded saddle-bag draped around your neck, and never even notice it, except occasionally if you needed to feel good about yourself.
TDD – as always i mean by this “the modern software development synthesis” broke me of a lot of “good programming practice” habits that were not in fact good programming practice, but it took me a really long time to get past this one. i was already pretty much a TDD master before i finally set it aside.
why set implementation inheritance aside?
maybe you’ve never seen hardcore implementation inheritance. i see it all the time, particularly in older larger codebases dominated by a so-called “senior architect” who memorized the GOF book in ‘95 and hasn’t shipped value in the last 20 years.
but if you’re wondering, here: this chart – part 1 of 3 – is illustrative. almost none of those boxes is an interface. at the bottom of that dependency tree there are leaf nodes that have upwards of seven or ten implementing super-classes. every one of them with dozens of methods, every one a partial override of its super.
we don’t ship more value faster by juggling more balls, but by juggling fewer. implementation inheritance always adds balls to what you have to juggle in your head while you’re working.
so let it go. if you’re having trouble seeing a new design without it, come find me, or any of dozens of serious TDD’ers out there. we like solving design problems. we do it the way people work crosswords in the sunday times. ask us, you’ll see.