Modular Design CS Thinking Example 2
Follow the full solution, then compare it with the other examples linked below.
Example 2
mediumA game program needs: a menu system, a game loop, a scoring system, and a high-score table. Design a modular structure showing how these components interact.
Solution
- 1 Step 1: Create four modules: Menu, GameLoop, ScoreTracker, HighScoreTable. Each handles one responsibility.
- 2 Step 2: Define interfaces between modules: Menu calls GameLoop.start(). GameLoop uses ScoreTracker.addPoints(). When the game ends, GameLoop passes the final score to HighScoreTable.checkAndAdd().
- 3 Step 3: Each module can be developed and tested separately. If the scoring rules change, only ScoreTracker needs updating.
Answer
Four modules (Menu, GameLoop, ScoreTracker, HighScoreTable) with clear interfaces between them. Each can be developed and modified independently.
Good modular design minimises dependencies between modules (low coupling) while keeping related functionality together (high cohesion). This is a core principle of software engineering.
About Modular Design
Modular design is the practice of structuring a program as a set of independent, self-contained modules, each responsible for a single, well-defined task. Modules communicate through clear interfaces, making the system easier to build, test, debug, and maintain.
Learn more about Modular Design โMore Modular Design Examples
Example 1 easy
A student writes a 200-line program as one big block of code. Suggest how they could improve it usin
Example 3 mediumList three benefits of modular design and give a specific example of each benefit in the context of
Example 4 hardExplain the concepts of coupling and cohesion in modular design. Why do we want low coupling and hig