In one of the training courses I've been giving on object-oriented design techniques, I was discussing two principles from the GoF book, Design Patterns: Elements of Reusable Object-Oriented Software :
- "Program to an 'interface', not an 'implementation'." (Gang of Four 1995:18)
- Composition over inheritance: "Favor 'object composition' over 'class inheritance'." (Gang of Four 1995:20)
And I was thinking how I can make those two phrases stick more. And a thought occurred to me that perhaps if we make those principles rhyme, it'll be easier for developers to remember, and become more effective.
Rhyme-as-Reason Effect
In one study [1], researchers compared the perceived truthfulness of rhyming vs. similar non-rhyming statements. For example:
"What sobriety conceals, alcohol reveals" vs "What sobriety conceals, alcohol unmasks"
Which one do you find is true (or more truthful)?
Here's another one.
"Caution and measure will win you treasure" vs "Caution and measure will win you riches"
The study suggested that "rhyme, like repetition, affords statements an enhancement in processing fluency that can be misattributed to heightened conviction about their truthfulness."
In other words, rhyming makes statements easier to understand. Which, in turn, makes them appear more accurate.
Object-Oriented Design Principles with Poetry
Here's my attempt at making those two principles rhyme.
Program to an interface, not to an implementation.
An implementation is good and fine, an interface is a wiser design.
Programming to an implementation is logical, programming to an interface is exceptional.
Programming to an implementation is what is needed, programming to an interface is why we succeeded.
Favor composition, over inheritance.
Inheritance if you must, in composition we trust.
Next time…
So the next time I get a chance to run another training course on object-oriented design techniques, I'll give these rhymes, some good times.
If you have rhymes of your own, please feel free to hit the comments.
[1] McGlone, M.S., and Tofighbakhsh, J. (2000) Birds of a feather flock conjointly (?): rhyme as reason in aphorisms. Psychological Science, 11:424-28.
No comments:
Post a Comment