Chapter 4: The Seam Model

A seam is a place where you can alter behavior in your program without editing in that place.

Pulling individual classes out for unit testing usually means breaking a lot of dependencies — and you hit that work regardless of how “good” the design supposedly is. Doing it changes what “good design” even means to you, and it pushes you to stop seeing a program as a flat sheet of text.

Let’s take a look at an example, a function in C++.

Why seams matter

The biggest challenge in getting legacy code under test is breaking dependencies. Sometimes they’re small and localised; in bad cases they’re numerous and spread throughout the codebase. The seam view helps you spot the leverage points already present in the code. If you can replace behaviour at a seam, you can selectively exclude a dependency in your tests — or substitute different code there to sense conditions and write tests against them. Often that’s just enough to get a foothold for more aggressive work.

Enabling point

Every seam has an enabling point — a place where you can make the decision to use one behavior or another.

Source

Working Effectively with Legacy Code, Michael Feathers — Chapter 4, The Seam Model.