Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jayzz55/3bea117e9f075f0b98c6 to your computer and use it in GitHub Desktop.
Save jayzz55/3bea117e9f075f0b98c6 to your computer and use it in GitHub Desktop.

5: Reducing Costs with Duck Typing

Duck types = public interfaces not tied to any specific class

It's not what an object is that matters, it's what it does.

Concrete code is easy to understand, but costly to extend. Abstract code may initially seem more obscure but, once understood, is far easier to change.

Once you begin to treat your objects as if they are defined by their behavior rather than by their class, you enter a new realm of expressive design.

Recognizing Hidden Ducks

Case statements that switch on class, kind_of?, is_a?, and responds_to? are potential ducks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment