Modularity divides a large program into smaller, more manageable tasks. Each module handles one job, can stand on its own, and can be tested independently. This makes larger problems easier to understand and reduces debugging time. section 20.2
A module works like a black box: identify its inputs, the task it performs, and its outputs without needing to inspect its implementation. Abstraction hides those implementation details so the module can be reused. section 20.2 section 21.0
Useful ways to recognize modular design include:
- Separate repeated work into a function instead of rewriting the same steps for every input. section 21.0 section 29.8
- Give each class a focused set of data attributes and methods, then use its objects consistently. section 34.6 section 34.0
- Build on libraries that provide tested and debugged solutions rather than implementing every task from scratch. section 35.0
A modular movement handler
In a tag game, an event handler decides which player should move and in what direction. The Player class contains the movement logic, so that logic is written once and reused by every Player object. The handler stays readable because it delegates coordinate changes to move(). section 38.3









