The rule of three is a refactoring heuristic: after similar behavior has been implemented about three times, introduce an abstraction for it. Waiting until then balances duplicated code against premature generalization, because repeated use cases reveal what the abstraction should support. section 4.3.2
Use the heuristic as a practical refactoring guide:
- Allow the first implementation to remain concrete. section 4.3.2
- Observe the use cases that emerge when similar behavior is repeated. section 4.3.2
- Refactor around the third implementation to provide a better-fitting abstraction. section 4.3.2
