Hello chaps. My christmas and new year holidays are nearly over, and to be honest I'm looking forward to going back to work. Sarah is already back at work and even with christmas toys to play with it's still a bit boring on my own. I've spent a lot of time mucking about on Facebook and playing with the rats.
For christmas this year Sarah gave me a lovely classical guitar. I owned one when I was living in Colorado a few years ago, it's good fun having one again that I can play some simple tunes on. :D I wrote a guitar tuner yonks ago, and so it has been given a bit of a dust off recently.
I've put some christmas money towards ordering a new push bike (in the sale of course). It'll replace the one I've got that's very heavy, very rusty, and in need of several repairs that the repair shop tell me aren't worth the expense. The new one is a bit lighter and has fancy hub gears that should be easier to maintain. I'll be able to pick it up this Sunday or Monday, I'm quite excited.. :D
I'm going to a pantomime tomorrow with Dad and some of his friends. Should be good fun I reckon. Though it does mean I'll miss out on some bathroom shopping with Sarah. :/ I'm sure she won't pick anything too hideous. :p
I've recently noticed that deciding class inheritance requires looking at the behaviour you want from your classes a lot more than I'd previously realised. Looking at what they represent isn't enough. Looking at the classic Rectangle and Square example in OOP..
If we are interested in creating a couple of read-only and immutable classes (Get methods only), then everything we can ask of a Rectangle we can also ask of a Square (GetWidth() and GetHeight()). So leading from this we'd be inclined to make Square inherit from Rectangle.
Alternatively.. If we are interesting in write-only classes and we focus only on the Set methods then we come to the opposite conclusion. Having Rectangle as base would imply that Square would need to implement SetWidth() and SetHeight(), not very clever. Only SetSize() makes sense for both shapes, and so we conclude that Square should be the base, with Rectangle derived (presumably SetSize() on a rectangle would set both the width and height in one go).
Can this sort of issue (where looking at different behaviour requirements for the same set of objects could lead to different decisions about inheritance) crop up with real classes? Or is this an artifact of the slightly dodgy example? I'm inclined to think it is a real problem, but I can't think of an instance in which this has bitten me for real.
Is there a name for this kind of analysis? Can any of the more experienced programmers out there suggest a good book?
Also.. What happens if you have an existing class hierarchy and are interested in adding a new feature, only to discover that the new feature would require a different inheritance layout? (Maybe we have read-only shape classes, and want to extend them to be mutable).
 Hmm, books always say that classes should focus on behaviour more than anything else.
 We probably shouldn't have a Square class, or at least it should be unrelated to Rectangle.
Finally! That old crufty "pauldoo" journal I started when in 1st year uni and abandoned after ten minutes has expired. This "pdoo" one has been renamed to my preferred title. :)
Apparently all linky things from the old one should have been automagically updated to follow.