Which approach does OOP

Black Consulting GmbH

In their book "99 Bottles of OOP", Sandi Metz and Katrina Owen want to show that everything you need to know about object-oriented programming ("OOP") can be found in the American folk song "99 Bottles of Beer" and its programming implementation. We received a pre-release version of the book and are checking if that's true ...

The American software developer, author and regular speaker at software conferences, Sandi Metz, has more than 30 years of experience in the development of large, object-oriented systems. Her OOP roots go back to Smalltalk, the »mother of object orientation«. In the past few years she has made a name for herself with numerous lectures on object-oriented programming and design.

With "Practical Object-Oriented Design in Ruby" Sandi already has the Reference work on object-oriented design for the Ruby programming language and beyond presented. At Amazon, for example, the book achieved 4.8 out of 5 stars, ranked 3rd among Ruby books and 9th in the "Object-Oriented Software Design" category.

Katrina Owen is a software developer at Github with a passion for automation and refactoring. She also speaks regularly at software conferences and runs an open source platform for improving programming skills at exercism.io.

The idea and the red thread of the book is to optimize an initially simple and more procedural solution to the "99 Bottles of Beer" problem through a series of small refactoring steps based on object-oriented principles so that in the end a "clean" and thus maintainable, object-oriented implementation is available. For the two authors, "Code clarity" is a mandatory requirement, regardless of which development paradigm one follows:

Code is read many more times than it is written […] Writing code is like writing a book; your efforts are for other readers.

The book is aimed at both beginners and experienced developers. The latter could, however, have difficulties with the very small-scale and sometimes almost slavish-looking, test-driven development steps. But if you get involved, you will definitely take something away from the reading!


In the first chapter, various approaches to solving the problem (»code designs«) are presented and evaluated in detail. In addition, the topic of (code) design is basically dealt with:

Design is […] about picking the right abstractions.

The theoretical foundation for the corresponding evaluation options for source code (opinion vs. facts; ABC, cyclomatic complexity, SLOC) is conveyed using extensive code examples. In addition, the first, basic programming principles, such as DRY (Don't Repeat Yourself) and object-oriented terminologies, such as messages and methods or how to differentiate them, are explained.

At the end of the chapter, one approach remains of the various solution options which solves the "99 Bottles of Beer" problem in a simple and fast way without regard to OOD or other programming principles and is therefore "good enough". The authors appropriately call this first implementation "Shameless Green".

Chapter two is all about test-driven development ("TDD"). "Shameless Green" is completely redeveloped line by line, but this time following the TDD principle. In addition, initial refactoring concepts are discussed. The spiritual fathers of the second chapter are clearly Kent Beck and Robert C. Martin. The solution will be step by step test-first developed. Each step is explained in detail along with alternatives and variants. Here, for the first time, you get the feeling of looking over the shoulder of the two authors while programming. We found the following statement particularly noteworthy in this chapter:

Programmers take the DRY principle to extremes, as if they're allergic to duplication. DRY is important but if applied too early, and with too much vigor, it can do more harm than good.

In chapter three, as in real life, a new requirement appears, with which the previous solution approach reaches its limits. With the SOLID principle, it is now "correctly" object-oriented for the first time. In addition, code smells are explained and design patterns are touched upon. Most of the chapter is devoted to refactoring. Abstract concepts are "peeled" piece by piece from the code using the so-called swarm rule. It is noteworthy, but in keeping with their attitude towards DRY mentioned above, that the authors use differences and not equality to point the way to the concepts hidden in the code:

Difference holds the key to understanding.

Concept density as well as practical relevance of chapter three are overwhelming in a positive sense. In passing, Avdi Grimm's "Column Heading Technique" is also a very practical aid for one of the two major problems in computer science, finding a name.

After looking over the shoulder in the previous chapters, chapter four is like a look into the head of the authors while programming or like a round of pair programming with the two of them. The code is refactored line by line, literally, horizontally. If only one line can be adjusted at a time, of course, further tricks are sometimes required, for example if the signature of a method is changed, as this naturally affects other places in the code. But the authors also provide suitable answers here. The horizontal refacorting approach may seem pedantic to small-scale, but the code remains constantly "green" and can therefore be delivered at any time. Every step is secured here as in mountaineering; The book cover says “Code Responsibly” for a reason. The procedure in small steps and the strict application of a few rules also means that the relevant technical concepts gradually reveal themselves from the code, as if by themselves:

You don’t have to understand everything before you can do anything.

Chapter five then swings further in the direction of object orientation with »Separating Responsibilities«. As a small talk and thus OO veteran, Sandi first gets to grips with the conditionals. Patterns in the code indicate the Primitive obsession-Code Smell, which then by means of Extract Class-Refactoring is done. Immutability is presented and related, but premature performance concerns are dispelled:

Your goal is to optimize for ease of understanding while maintaining performance that's fast enough. Don’t sacrifice readability in advance of having solid performance data.

Or, to use Kent Beck's words:

Make it work. Make it right. Make it fast. ... in that order.

In the final chapter six, the so far still strongly procedural code is then object-oriented. The Liskov substitution principle, polymorphism and inheritance are applied and explained, appropriate classes are created for the special cases of the song and the remaining conditionals are transferred to a factory:

Factories don’t know what to do: instead, they know how to choose who does. They consolidate the choosing and separate the chosen.

As the code now Open is, the additional requirement from chapter three, which set the entire refactoring process of »Shameless Green« in motion, can easily be implemented, true to Kent Beck's motto:

Make the change easy (warning: this may be hard), than make the easy change.

With the help of metaprogramming, the conditionals disappear from the factory and of course all of this takes place again step by step (»horizontal refactoring«), and secured by tests.

The practical relevance of the authors becomes clear again in this chapter, because they always first address the problem through the solution. So not: "Here is heredity, let's look for problems that we can solve with it," which then usually leads to animal or vehicle classes, but: "Here is our problem, let's see if we can solve with inheritance «, which leads to the aha effect that characterizes the book.


Martin Fowler has published the corresponding reference work on refactoring, unfortunately the rear part of the book reads as exciting as a collection of cooking recipes. “99 Bootles of OOP”, on the other hand, is a look into the kitchen and shows impressively and comprehensibly how refactoring is actually used and how it helps you to explore the respective problem domain. In our opinion, a very valuable, additional benefit of refactoring. But borders are not kept secret either:

The truth about refactoring is that it sometimes makes things worse.

We had a beta version of the "Ruby Edition" of the book, which suggests that other editions in other programming languages ​​will follow. It is not an introduction to Ruby, but rather to object-oriented programming and its practices in particular. The examples can be transferred to other object-oriented languages, whereby the authors' background in dynamically typed languages ​​such as Smalltalk and Ruby naturally also allows them to resort to corresponding OO concepts such as duck typing, which require detours in statically typed languages.

At the entry level, Sandi Metz and Katrina Owen create a high concept density with good practical relevance in the book. Even if the song and its solution may seem trivial, consistent refactoring from an OOD point of view results in »clean code« in the end. The book is linguistically as well as didactically very well structured and reads fluently from beginning to end, which is quite remarkable in the genre and with which the authors pleasantly differentiate themselves from the spiritual father "Uncle Bob". We have rarely found refactoring and TDD described in such a comprehensible manner. The title of the book says it all: practical programming practices are given a little more weight than object-oriented design. But that doesn't detract from the book, on the contrary; on the one hand, with »Practical Object-Oriented Design in Ruby«, the appropriate addition to OOD is already available and, on the other hand, this is only consistent, because:

Object-oriented design is about introducing objects as late as possible!

At USD 49, the book is not exactly in the lower price segment. The authors also take an interesting approach to the question of "fair" pricing: if the price is too high for you, you should send them a postcard (!) And receive the book for free.

We particularly liked that the book does not present a finished implementation, but that the many small decisions, branches and dead ends that a developer is confronted with in the course of his work are presented and discussed. It's about the way and not the goal, because design is also a process. If you help to program while reading, the problem becomes real and the book can fully live up to its claim (“A Practical Guide to Object-Oriented Design”). The book contains enough code for this ...


Bibliographical information

Sandi Metz, Katrina Owen

99 Bottles of OOP - A Practical Guide to Object-Oriented Design

488 pages

Potato Canyon Software, LLC., Durham, North Carolina

ISBN-10: 1-944823-00-X

First edition

Copyright 2016

Version 0.4 beta from February 13, 2017