Modular Design CS Thinking Example 2

Follow the full solution, then compare it with the other examples linked below.

Example 2

medium
A 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. 1
    Step 1: Create four modules: Menu, GameLoop, ScoreTracker, HighScoreTable. Each handles one responsibility.
  2. 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. 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