You are previewing Practical Object-Oriented Design in Ruby: An Agile Primer.

Practical Object-Oriented Design in Ruby: An Agile Primer

Cover of Practical Object-Oriented Design in Ruby: An Agile Primer by Sandi Metz Published by Addison-Wesley Professional
O'Reilly logo

Chapter 6. Acquiring Behavior Through Inheritance

Well-designed applications are constructed of reusable code. Small, trustworthy self-contained objects with minimal context, clear interfaces, and injected dependencies are inherently reusable. This book has, up to now, concentrated on creating objects with exactly these qualities.

Most object-oriented languages, however, have another code sharing technique, one built into the very syntax of the language: inheritance. This chapter offers a detailed example of how to write code that properly uses inheritance. Its goal is to teach you to build a technically sound inheritance hierarchy; its purpose is to prepare you to decide if you should.

Once you understand how to use classical inheritance, the ...

The best content for your career. Discover unlimited learning on demand for around $1/day.