Notes on Practical Object-Oriented Design

I learned a lot from Practical Object-Oriented Design by Sandi Metz. The author's emphasis on messages between objects as a fundamental unit of design was a refreshing and rewarding departure from other OOD books I've read. Overall, the book reminded me to embrace the frequent lack of information in software projects, resist over-design at the start, and preserve the ability to change code when information does eventually come.

Lessons

A few of the personally memorable lessons were:

  • Depend on things that change less often than the thing you're working on
  • Consider the roles an object plays and a sensible interface for that role
  • Ask for what rather than telling how
  • Checking types or properties might suggest a hidden duck type

Other ideas and techniques

  • Rigorously enforce the Single Responsibility Principle. Even simple values may become more complicated with time, so hiding them behind methods rather than properites might be a good idea.
  • Use flow diagrams to model messages and uncover interfaces
  • Isolate dependencies - these may include the name of a class, the name of a message (method), required arguments, or order of arguments.
  • Test public interfaces. Testing public interfaces provides good coverage without tying tests to implementation details. Mock when you need to know if a message is sent.
  • Hide imperfect implementation behind a good interface until you have more information

I highly recommend the book.