Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Sandi Metz, Katrina Owen, TJ Stankus

Rating 4.0 AI initial rating

It turns out that everything you need to know about Object-Oriented Design (OOD) can be learned from the "99 Bottles of Beer" song. Well, perhaps not everything, but quite certainly a great many things. The song is simultaneously easy to understand and full of hidden complexity, which makes it the perfect skeleton upon which to hang lessons in OOD. The lessons embedded within the song are so useful, and so broad, that over the last three years it has become a core part of the curriculum of Sandi Metz’s Practical Object-Oriented Design course. The thoughts in this book reflect countless hours of discussion and collaboration between Sandi, Katrina Owen, and TJ Stankus. These ideas have been battle-tested by hundreds of students, and refined by a series of deeply thoughtful co-instructors, beginning with Katrina. While none of the authors have the hubris to claim perfect understanding, all have learned a great deal about Object-Oriented Design from teaching this song, and feel compelled to write it all down. Therefore, this book, now in its second edition. We hope that you find it both useful and enjoyable.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on guide that uses the "99 Bottles of Beer" song to teach practical object-oriented design: how to move from working-but-messy code to flexible, well-factored code through disciplined refactoring and test-driven development. Best for developers who can write code but want to think more clearly about design, duplication, and change. 【Book Arc】 - **Opening (~0%–10%)**: Frames the book's premise—the song is simple to understand yet hides real complexity—and introduces the central tension between DRY code and the cost of understanding. It critiques an "Incomprehensibly Concise" first attempt that is technically DRY but expensive to change. - **Early (~10%–30%)**: Establishes the workflow: write a failing test, get to "Shameless Green" (the simplest code that passes), then refactor. Introduces test structure (setup, do, verify), cyclomatic complexity as a rough guide, and the problem of conditionals multiplying as requirements change (the "six-pack" requirement). - **Middle (~30%–55%)**: The core methodology—the Flocking Rules—is applied iteratively. Readers learn to find the verses most alike, replace differences with sameness, extract concepts into named methods, and gradually cut over refactorings using defaulted arguments as temporary shims. The chapter walks through removing special cases for verses 2, 1, and 0 until a single abstract template produces every verse. - **Late (~55%–85%)**: Excerpts do not cover this range in detail; based on the arc, this stage likely returns to the six-pack problem and extends the design to handle new requirements, testing whether the refactored code is genuinely open to change. - **Ending (~85%–100%)**: Excerpts do not cover the closing chapters; the book presumably consolidates lessons on OO mindset, naming, and judging design quality. 【Key Takeaways】 - **DRY is not free** (Opening): Every extraction adds indirection, which raises the cost of understanding. Duplication removal only pays off when it lowers the cost of change more than it raises comprehension cost. - **Shameless Green first, design second** (Early): Write the simplest code that passes tests—even if it contains duplication and conditionals—then refactor once requirements are clear. Premature abstraction is a trap. - **Conditionals are the bane of OO** (Early): Each new special case (like the six-pack) compounds branching logic. The goal is to replace case statements with polymorphic, message-driven code. - **The Flocking Rules provide a repeatable refactoring path** (Middle): Find the most alike cases, make them more alike step by step, then identical; extract each difference into a named method and send messages instead of embedding logic. - **Name concepts, not syntax** (Middle): Methods like `container`, `quantity`, `pronoun`, and `action` capture domain meaning. Good names make the code's story legible and reduce mental clutter. - **Gradual cutover keeps code deployable** (Middle): Use defaulted arguments (e.g., `:FIXME`) as temporary shims so some callers can pass new arguments while others remain unchanged—then clean up. - **"Sending messages" vs. "calling methods"** (Opening): The message-sending mindset encourages senders to be ignorant of receiver implementation, fostering independence and maintainability. - **Tests drive specificity** (Early): As tests get more specific, well-factored code gets more generic; poorly factored code stays equally specific, accumulating one branch per case. 【Reading Tips】 - **Deep-read the Flocking Rules chapters** (Middle): This is the book's methodological core. Follow the step-by-step refactorings with the code in front of you—the value is in the process, not the final listing. - **Skim the early critique of "Incomprehensibly Concise"** if you already understand DRY trade-offs; focus instead on the transition to Shameless Green. - **Do the exercises**: The book is designed as a practicum. Attempt each refactoring before reading the solution; the lessons stick through doing, not reading. - **Watch for hard spots**: The gradual cutover with defaulted arguments and the iterative removal of special cases (verses 2, 1, 0) are the most demanding sections—slow down there. - **Take away the mindset, not the Ruby**: The specific code is Ruby, but the principles—message sending, naming concepts, incremental refactoring—transfer to any OO language. 【Coverage Limits】 This guide is based on stratified excerpts covering roughly the first half of the book; the late and ending chapters (including the return to the six-pack problem and final consolidation) are not represented, so claims about those stages are inferred from the book's stated arc rather than excerpt content.
Page 9
1. Your purchase entitles you to a single, non-transferable license for your personal use of the ebook related files. You may read and download the ebook you...
View in text
Excerpt 2
e; there will never be a time when the code can do anything which is not explicitly tested. However, in Listing 2.8: Generalized Verse, as the tests get more...
View in text
Excerpt 3
concrete variant is a generalized verse abstraction. If you could find this abstraction, you could use it to reduce the four- branch case statement to a sing...
View in text
Excerpt 4
ous that: "99" must represent the same concept as: number-1 As always, you must name this concept, create a method, and send the message in place of the diff...
View in text
Excerpt 5
copy could be re-used in the following verse, saving seven more object creations for a total of eight altogether. Over the course of the song, caching could...
View in text
Excerpt 6
d, or occasionally return something you don’t expect, force you into a paranoid programming style. These untrustworthy objects require senders of messages to...
View in text
Excerpt 7
plug BottleVerse into Bottles and tests fail, the rules of refactoring say you must undo and fix the offending code. If you 5. Forward messages from the orig...
View in text
Excerpt 8
ew.verse(1) 20 end 21 22 def test_verse_0 23 # ... 24 assert_equal expected, Bottles.new.verse(0) 25 end 26 end
View in text
Tags
AI categories
Programming LanguageSoftwareCode
Publish Year: 2020
Language: English
Pages: 499
File Format: PDF
File Size: 3.8 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…