[閱讀筆記] Clean Code — Chapter 12 Emergence
1 min readJan 31, 2021
Getting Clean via Emergence Design
• Runs all the tests
• Contains no duplication
• Expresses the intent of the programmer
• Minimizes the number of classes and methods
Simple Design Rule 1: Runs All the Tests
- A system that is comprehensively tested and passes all of its tests all of the time is a testable system.
- A system that cannot be verified should never be deployed
Simple Design Rule 2: No Duplication
- Duplication is the primary enemy of a well-designed system
- Duplication: Lines of code that look exactly alike are
- TEMPLATE METHOD
public void accrueVacation() {
calculateBaseVacationHours();
alterForLegalMinimums();
applyToPayroll();
}private void calculateBaseVacationHours() { /* ... */ };
abstract protected void alterForLegalMinimums();
private void applyToPayroll() { /* ... */ };
Simple Design Rule 3: Expressive
- Code should clearly express the intent of its author
- How to:
1. Choosing good names
2. Keeping your functions and classes small
3. Using standard nomenclature (ex. standard pattern names)
4. Well-written unit tests
Simple Design Rule 4: Minimal Classes and Methods
- Take rule 1–3 too far → too many tiny classes and methods
- Overall system small while we are also keeping our functions and classes small