Finding Seams in Legacy Code
You'll learn how to identify strategic modification points in legacy code that let you change behavior without directly editing dangerous areas.
What Is a Seam?
A seam is a place in your code where you can alter behavior without editing the code at that location. Think of it like a light switch: you don't modify the wiring inside your walls to turn a light on or off—you use the switch as an interface to change the behavior.
In legacy code, seams are your safe modification points. They're the boundaries where you can inject new behavior, intercept calls, or substitute implementations without touching fragile, untested code that might break.
Why Seams Matter
Remember the Legacy Code Dilemma? You need tests to safely refactor, but you need to refactor to add tests. Seams break this cycle. They let you introduce tests and modify behavior from outside the scary code, keeping your changes contained and reversible.
Common Types of Seams
Object seams: Points where you can substitute one object for another (dependency injection points, even if informal).
Preprocessing seams: Compile-time or build-time substitution points.
Link seams: Where you can swap implementations at link/load time.
The key is recognizing these boundaries already exist in your code—between functions, classes, modules, or configuration points—even if they weren't designed as extension points.
Finding Seams in Practice
Look for:
- Function/method call boundaries
- Constructor injection points (or places that could be)
- Module imports or includes
- Configuration loading points
- External system boundaries (databases, APIs)
You're identifying where behavior flows across a boundary you could potentially control.
Key Takeaway: Seams are existing or potential boundaries where you can change behavior from the outside, giving you safe leverage points to test and modify legacy code without invasive surgery.