The Three Ideas

The Three Ideas: Find What Changes and Fence It Off, Program to an Interface, Not a Class, Prefer Composition to Inheritance.

Updated

  1. Find What Changes and Fence It Off (Apprentice): When the part of a program that changes every week is mixed into the part that shouldn't change, every change risks the rest; finding what changes and giving it a home of its own, behind one wall, is the idea behind almost every design pattern, and it comes with two words worth knowing: coupling and cohesion.
  2. Program to an Interface, Not a Class (Apprentice): When checkout asks for a card reader by name, every new way to pay means editing checkout; asking instead for "something that can take a payment", a promise any class can keep, lets a gift card, or anything else, plug in without checkout changing at all.
  3. Prefer Composition to Inheritance (Apprentice): When every combination of options becomes its own subclass, the classes multiply until a burrito with extra cheese and no onion needs a class of its own; building an item from parts it holds (composition) instead of from a family tree of subclasses (inheritance) turns each new option into one new part.