Scott Hanselman, with guest Bob Martin #145
For yesterday's "Podcast Workout Session", I listened to Episode #145 of Hanselminutes by Scott Hanselman, with guest Bob Martin. I started listening to Hanselminutes a few weeks ago, so now I'm listening to the podcasts backwards in order to catch up (only 139 shows to go!).
The show is the first of three with Bob Martin discussing SOLID principles (see below), which are a set of guidelines for developing maintainable software. One of the portions of the discussion really resonated with me, in that it's a problem I've struggled with about Object Oriented Design (OO) in the past. One of the benefits of OO is that it allows related objects to be used interchangeably, without having to write new code. Scott uses the example of the relationship between a Square and a Rectangle. In the physical world, there is a very clear relationship between a Square and a Rectangle; on the surface, they have the same defining characteristic: 4 sides, 4 right angles. But when you try to model these two seemingly-related objects in code, the relationship breaks down. A Rectangle can have differing height and width characteristics, but the Square's sides are all equal; this is enough to make the relationship between the two objects in code very problematic when trying to use Square and Rectangle interchangeably. In the past, I've gone to great lengths to make similar relationships work in code, and eventually discovered that the relationship simply wouldn’t (or shouldn’t) work. It's comforting to know that programmers better than I have had these problems.
The show in one sentence: "It is completely possible for a relationship between objects to make perfect sense in English and to make no sense at all in software."
For the morbidly curious:
S - Single Responsibility Principle
O - Open Closed Principle
L - Liskov Substitution Principle
I - Interface Segregation Principle
D - Dependency Inversion Principle
(via Justin)