Key Points

  • Class interfaces should provide a consistent abstraction. Many problems arise from violating this single principle.

  • A class interface should hide something—a system interface, a design decision, or an implementation detail.

  • Containment is usually preferable to inheritance unless you're modeling an "is a" relationship.

  • Inheritance is a useful tool, but it adds complexity, which is counter to Software's Primary Technical Imperative of managing complexity.

  • Classes are your primary tool for managing complexity. Give their design as much attention as needed to accomplish that objective.

Get Code Complete, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.