Replace Hard-Coded Notifications with Observer
Summary
The article explains the refactoring 'Replace Hard-Coded Notifications with Observer' to remove persistence side effects from domain subclasses and keep domain logic pure. It outlines three concrete steps: emit events from the domain, derive contextual path information from the object graph, and subscribe in the application layer to perform persistence. The author demonstrates how this decouples domain behavior from side effects, shows DOM listener parallels, and highlights that the approach is idiomatic in JavaScript. A sidebar describes how Claude Code performs text-based refactorings (pattern recognition and string edits) and notes its strengths and limitations. The article closes with guidance on when to apply the refactoring and links to further reading in Refactoring to Patterns.