Back to Home

Article

Effective Design Patterns and Poetry

July 19, 2015
By Lorenzo Dee
By Lorenzo Dee
Reading Time : 3.5
 minute
s
Effective Design Patterns Banner
Back to Home

Article

Effective Design Patterns and Poetry

July 19, 2015
By Lorenzo Dee
By Lorenzo Dee
Reading Time : 3.5
 minute
s

Lorenzo tries to make design patterns principles easy to remember through poetry.

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 :

Design Patterns Book
  • “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.

[1] McGlone, M.S., and Tofighbakhsh, J. (2000) Birds of a feather flock conjointly (?): rhyme as reason in aphorisms. Psychological Science, 11:424-28.

Originally posted at: Effective Design Patterns and Poetry

Share

Key Topics

Internship 2023 Image Banner

Intern @ O&B

GROW WITH US AND
MAKE A DIFFERENCE

Apply for Internship
Internship 2023 Image Banner

Intern @ O&B

GROW WITH US AND
MAKE A DIFFERENCE

Apply for Internship