本文由 AI 分析生成
建立時間: 2026-03-28 來源: https://www.huanlintalk.com/2024/09/avoid-premature-abstraction.html?m=1
Summary
Michael Tsai argues against premature abstraction in software design, pushing back on the common interpretation of SOLID/OCP that encourages designing for future flexibility upfront. The key evidence: an interview with Uncle Bob (Robert C. Martin) where even he admits he now starts with concrete implementations and lets abstraction emerge from code pressure, rather than designing abstractions first.
Michael Tsai 反對軟體設計中的過早抽象,反駁對 SOLID/OCP 的常見解讀——即鼓勵預先設計未來靈活性。關鍵證據:對 Uncle Bob(Robert C. Martin)的訪談,即使他本人也承認現在先從具體實作開始,讓抽象從程式碼壓力中浮現,而非先設計抽象。
Key Points
- Premature abstraction creates maintenance debt: layers of indirection, abstract classes for scenarios that never materialize, increasing complexity without delivering value
- Uncle Bob’s updated view (2024): “I start with concrete code, then let the concrete world force me to find the abstractions” — contradicts the traditional SOLID didactic
- Martin Fowler’s rule of three: refactor to introduce abstraction only after the same pattern appears three times — simple, concrete, practical
- YAGNI (You Aren’t Gonna Need It) and KISS as counterweights to SOLID and DRY
- Real-world testimony: maintaining a heavily abstracted legacy system with DI/layering but no documentation is harder than maintaining a simple top-down system with no docs
- Abstractions have costs: each layer is indirection that a future maintainer must trace through
Insights
The Uncle Bob interview creates a productive tension: the person most associated with Clean Code and SOLID is now advocating a “code first, abstract second” approach. This doesn’t mean SOLID is wrong — it means the popular teaching of SOLID (pre-emptively abstract everything) is a misapplication. The underlying insight is that good abstractions come from understanding actual concrete pain points, not from imagining future pain points. Abstractions built from real friction tend to fit well; abstractions built from imagined friction tend to be wrong-shaped and costly to undo.
Connections
Raw Excerpt
當我的 code 越加越多,會令我覺得如果不加個抽象層來應對,就很難繼續加入更多 code。換言之,程式碼迫使抽象層在我心中浮現。— Uncle Bob