login as:
~/abapcraft.dev — code, crafted in SAP
florin@s4hana:~/abap/posts/book-refactoring $ cat README.md

Refactoring — Martin Fowler

The bible of refactoring — a systematic catalogue of techniques for improving the design of existing code without changing what it does.

What the book is about

Written by Martin Fowler, Refactoring: Improving the Design of Existing Code is exactly what its subtitle promises. It is the definitive reference on the practice of changing the internal structure of code without changing its observable behavior.

That distinction matters. In the industry, “refactoring” is often used loosely to mean any kind of code change — rewriting, reorganising, cleaning up. Fowler is precise: refactoring means applying a named, behaviour-preserving transformation to improve the design. Each transformation is a small, safe step. The accumulation of those steps is what improves a system over time.

The book’s lasting contribution is not any single technique — it is the idea that refactoring is a discipline, with a vocabulary and a catalogue, not just an instinct you develop over years of experience. Naming a technique makes it communicable. A team that shares this vocabulary can talk about what they are doing and why.

The full catalogue is also available online at refactoring.com/catalog — a living reference that complements the book.

Refactoring principles

Why refactor? — Code that is not refactored degrades. Features are added without adjusting the surrounding design, duplication accumulates, and the system becomes harder to understand and change. Refactoring is the practice of paying back that debt continuously, so it never becomes unmanageable. It is not a separate activity from development — it is part of how development works.

When to refactor? — Fowler’s answer is: continuously, in small steps, as part of normal work. The Rule of Three is a useful heuristic: the first time you do something, just do it. The second time you do something similar, note the duplication. The third time, refactor. The most productive moment to refactor is just before adding a new feature — clean the area you are about to work in, then add the feature. The code is easier to extend, and the change is safer.

Selected techniques from the catalogue

Extract Function — take a block of code that can be understood as a unit and move it into its own function with a name that explains what it does. This is the most fundamental refactoring. A well-named function turns a comment into code.

Inline Function — the inverse of Extract Function. When a function’s body is as clear as its name, remove the indirection. Not every abstraction earns its keep.

Extract Variable — give a complex expression a name. This makes the code self-documenting and the expression reusable. The name is the documentation.

Change Function Declaration — rename a function or restructure its parameters so that its signature better communicates its purpose. A function’s name is its contract with the caller.

Introduce Parameter Object — when a group of parameters always travels together, replace them with a single object. This reduces argument lists, reveals a missing concept in the domain, and opens the door to moving behavior onto the new object.

Encapsulation

Encapsulate Record — replace a plain data structure with an object that controls access to its fields. This makes it possible to add behavior, enforce invariants, and change the internal representation without breaking callers. Raw data structures are a liability in large systems; encapsulated objects are an asset.

Encapsulate Collection — instead of exposing a collection directly, expose it through methods that control what callers can do with it. A class that hands out a raw list gives up control of that list entirely. Encapsulating the collection keeps the class in charge of its own state.

Simplifying conditional logic

Decompose Conditional — extract the condition and each branch of an IF statement into well-named functions. Complex conditionals are a primary source of unreadable code. Breaking them apart replaces a wall of logic with readable, named decisions.

Introduce Special Case — when multiple parts of the code check for the same special condition (a null, a default value, an edge case), replace all those checks with a special case object that provides the expected behavior automatically. This eliminates scattered conditionals and centralises the handling of the exception.

Personal statement

This is the book I return to when I want to understand what refactoring really looks like — not as a concept, but as a concrete sequence of named, safe steps. The examples are detailed and realistic. Some are immediately clear; others require more time to follow. The complexity of the examples reflects the complexity of the problems they solve, which is honest.

The catalogue is what makes the book a lasting reference rather than a one-time read. Along with refactoring.com/catalog, it is the resource I point to whenever a conversation about code quality needs to move from the abstract to the concrete.

For me, this is the bible of refactoring. If the other books in this series teach you why clean code matters, this one teaches you how to get there from where you are now.