Dependency Breaking Technique Executor
by @quochungto
Select and execute the right dependency-breaking technique from Michael Feathers' catalog of 24 named techniques (Part III of Working Effectively with Legacy...
Example 1: Parameterize Constructor (Java)
PaymentProcessor creates new DatabaseConnection("prod", 5432) in its constructor. Tests cannot run without a live database.
Technique: Parameterize Constructor. Add PaymentProcessor(DatabaseConnection db) constructor; original becomes this(new DatabaseConnection(...)). Tests inject new FakeDatabaseConnection(). Production callers unchanged.
Example 2: Extract Interface (Java)
UserNotifier holds a UserRepository field. Repository opens a database on construction; no way to substitute.
Technique: Extract Interface. Create empty IUserRepository; make UserRepository implements IUserRepository; change UserNotifier's field type. Compile β errors identify every method that must appear on the interface. Create FakeUserRepository for tests. Production unchanged.
Example 3: Push Down Dependency (C++)
OffMarketTradeValidator.showMessage() calls AfxMessageBox (Windows MFC) and g_dispatcher. Cannot test validation logic without the Windows GUI framework.
Technique: Push Down Dependency. Make showMessage() pure virtual in the base class. WindowsOffMarketTradeValidator holds real MFC code. TestingOffMarketTradeValidator overrides showMessage() with an empty body. Tests instantiate the testing subclass β validation logic is now testable without any UI framework. (See case study cs-012 in references/all-techniques.md.)
clawhub install bookforge-dependency-breaking-technique-executor