| 1 | # Deep Modules |
| 2 | |
| 3 | From "A Philosophy of Software Design": |
| 4 | |
| 5 | **Deep module** = small interface + lots of implementation |
| 6 | |
| 7 | ``` |
| 8 | ┌─────────────────────┐ |
| 9 | │ Small Interface │ ← Few methods, simple params |
| 10 | ├─────────────────────┤ |
| 11 | │ │ |
| 12 | │ │ |
| 13 | │ Deep Implementation│ ← Complex logic hidden |
| 14 | │ │ |
| 15 | │ │ |
| 16 | └─────────────────────┘ |
| 17 | ``` |
| 18 | |
| 19 | **Shallow module** = large interface + little implementation (avoid) |
| 20 | |
| 21 | ``` |
| 22 | ┌─────────────────────────────────┐ |
| 23 | │ Large Interface │ ← Many methods, complex params |
| 24 | ├─────────────────────────────────┤ |
| 25 | │ Thin Implementation │ ← Just passes through |
| 26 | └─────────────────────────────────┘ |
| 27 | ``` |
| 28 | |
| 29 | When designing interfaces, ask: |
| 30 | |
| 31 | - Can I reduce the number of methods? |
| 32 | - Can I simplify the parameters? |
| 33 | - Can I hide more complexity inside? |
| 34 |