Sweeping It Under the Rug
Explanation
Section titled “Explanation”Some code is overgrown and tangled. People call it spaghetti code. It is hard to understand, fix or extend (see Big Ball of Mud). Often you cannot make it go away. The pattern’s advice is to cordon it off.
How it works
- Identify the disordered parts of the system.
- Isolate them from the rest of the system.
- Start drawing boundaries where the parts are least tightly coupled. Coupling means how strongly parts depend on each other (see Coupling and Cohesion).
- Split global data into distinct data structures.
- Put a façade on the quarantined code. A façade is a clean front interface. It puts a “pretty face” on the unpleasantness.
A first step, not the end
A fresh interface around a run-down region can be the first step toward rehabilitation. That work is long and hard. Containment is also a first step toward Consolidation.
Example
Section titled “Example”A company has an old billing module with tangled code. The team finds the spots where it depends least on other modules and draws a boundary there. They split the shared data it uses into separate data structures. Then they add a small, clean interface in front of it. New features talk only to that interface. The mess stays inside the boundary.
Trade-offs
Section titled “Trade-offs”Containment does not remove the mess. It only fences it off. Rehabilitating the region is still long, hard work. At times, Reconstruction (rebuilding) may seem less painful than that work.
Diagram source
flowchart LR A[Rest of the system] --> F[Clean façade] subgraph Enclave[Quarantined code] F --> M1[Tangled part 1] F --> M2[Tangled part 2] endChecks
Section titled “Checks”- Disordered parts of the system are identified and isolated from the rest of it.
- Boundaries around the messy code start where coupling is lowest.
- Global data is split into distinct data structures.
- A façade fronts the quarantined code.
Related
Section titled “Related”- Big Ball of Mud
- Refactoring
- Technical Debt
- Coupling and Cohesion
- Shearing Layers
- Architecture Decay
- Information Hiding
Sources
Section titled “Sources”- Big Ball of Mud — laputan.org, accessed 2026-11-09