Working Effectively With Legacy Code — Changing Software (Part 1: Chapter 4)

This is Chapter 4 of the Working Effectively With Legacy Code series. If you haven’t read the previous Chapter 3.

Part 1 : Mechanics of Change:

Chapter 4: The Seam Model

What is Seam in Software?

The analogy is a seam in clothing: A line where two piece of fabrics are stitched together.

A seam in software as a place where two parts of the code meet and where something else can be injected. The piece on each side only touches the other right at the seam.

Why Seams?

One of the biggest challenges in getting legacy code under test is breaking dependencies.

The seam view of software helps us see the opportunities that are already in the code base. If we can replace behavior at seams, we can selectively exclude dependencies in our tests.

We can also run other code where those dependencies were if we want to sense conditions in the code and write tests against those conditions. Often this work can help us get just enough tests in place to support more aggressive work.

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

Types of Seam

The types of seams depends on the programming language we use. Each types of seams are categorized by the steps involved in compiling the code.

  • Preprocessing Seams: C and C++ provides with preprocessing tool. This preprocessing, a macro preprocessor runs before the compiler. We can use the preprocessing seams to replace calls to another independent piece of code.
#include “localdefs.h” // Example of macro preprocessor which can be used to provide some definition to external independent code
  • Link Seams: In programming languages, when a source file contains an import statement, the compiler checks to see if the imported class really has been compiled. We import those classes from classpath environment variables for eg; JDK path. We can replace those imported class and alter their behavior during by using dynamic linking. This link seams, should be different for test and production environments.
  • Object Seams: They are the most useful seams available in object-oriented programming languages. Object seams are mostly used to isolate the behavior while testing.
Figure: Cell hierarchy. (Source: Working Effectively with Legacy Code, page 41;

Here, the Cell Object provides Object Seams, since, Cell is an abstract class, and the value of object depends which we can isolate during test.

public Spreadsheet buildMartSheet(Cell cell) { …cell.Recalculate();… }

Chapter 3: Legacy Series

Chapter 5: Tools


MyView androidView;

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store