Profile picture of Jim Pruetting

Practical Object-Oriented Design in Ruby

Object-Oriented Design

Designing Classes with Single Responsibility

Managing Dependencies

Creating Flexible Interfaces

Reducing Costs with Duck Typing

Acquiring Behavior Through Inheritance

Sharing Role Behavior with Modules

Combining Objects with Composition

Designing Cost-Effective Tests

Key Takeaways

  1. Design for change: Make code easy to change without unexpected consequences
  2. Dependencies matter: Manage and minimize dependencies between objects
  3. Messages over objects: Design the messages first, then determine who should respond
  4. Interfaces not implementations: Make objects reveal what they do, not how they do it
  5. Composition flexibility: Choose composition over inheritance when appropriate
  6. Tests as design: Write well-designed code that is naturally testable
  7. Pragmatic approach: Remember no design principle is absolute; make context-appropriate trade-offs
  8. Incremental design: Don’t over-design upfront; let good designs evolve
  9. TRUE code: Create Transparent, Reasonable, Usable, and Exemplary code