Change by Addition, Feature Toggles, Strategy Pattern

#56 - Refactoring–The Discipline for Writing Good Code - Christian Clausen

Topic 13 of 18

Published Sep 20, 2021 · Clip 34:15–37:02 (2:47)

Christian explains changing code by addition: wrap original code in an if-else block (even duplicating it) and put new code in the else branch, controlled by a parameter — the original stays intact and switchable, so nothing is modified, only added. This generalizes into feature toggling and, for two customers needing different configurations, the strategy pattern — the most important refactoring in his book, turning an if into an interface with subclasses. The host notes feature toggles also enable A/B testing and rollbacks, and Christian lists benefits: continuous merging and deployment with the toggle off, releasing as a business decision (e.g., at a conference event), and building A/B testing on top.