Course contentsShow
← Software Engineering
Lesson 1767 of 1,93351. Legacy Code and Brownfield DevelopmentFree lesson

The Mikado Method for Large Refactorings

Using dependency graphs to break down complex refactorings into small, incremental steps that keep the system working.

The Mikado Method for Large Refactorings

What you'll learn: How to use dependency graphs to break down intimidating, large-scale refactorings into safe, incremental steps that keep your system running.

The Core Idea

The Mikado Method is a technique for tackling large refactorings by mapping out dependencies before you code. Instead of diving in and breaking everything, you make a small change, observe what breaks, document those dependencies, then revert. You repeat this process, building a graph that reveals the natural order for making changes safely.

Think of it like planning to move a heavy bookshelf: you can't just push it. First you remove the books, then unplug the lamp on top, then move the rug underneath. The Mikado Method helps you discover this sequence for code.

How It Works

  1. Set your goal (e.g., "Extract class UserValidator")
  2. Try the change naively and see what breaks
  3. Note each breaking dependency as a prerequisite node
  4. Revert completely to working code
  5. Pick the smallest prerequisite with no dependencies of its own
  6. Repeat until you've mapped all dependencies
  7. Execute bottom-up: complete leaf nodes first, working toward your goal

The graph you create shows exactly which refactorings must happen before others. Each node represents a small, testable change that leaves the system working.

Why This Works in Legacy Code

In legacy systems, dependencies are often hidden and tangled. The Mikado Method makes them visible without forcing you to hold a broken system in your head. You're always one revert away from working code. Your characterization tests (lesson 1758) act as the safety net that tells you when each small step is complete.

Key Takeaway: The Mikado Method transforms overwhelming refactorings into a clear, ordered dependency graph where each step is small, safe, and leaves the system functional.