Modular Design CS Thinking Example 1
Follow the full solution, then compare it with the other examples linked below.
Example 1
easyA student writes a 200-line program as one big block of code. Suggest how they could improve it using modular design.
Solution
- 1 Step 1: Identify distinct tasks in the program (e.g., reading input, processing data, displaying results).
- 2 Step 2: Break each task into a separate function or module with a clear name (e.g., readData(), calculateAverage(), displayResults()).
- 3 Step 3: The main program calls these modules in sequence. Each module can be developed, tested, and debugged independently.
Answer
Break the program into separate functions for each task. Each function handles one responsibility and can be tested independently.
Modular design divides a program into self-contained, reusable components. This makes code easier to read, test, debug, and maintain โ especially important as programs grow larger.
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 2 medium
A game program needs: a menu system, a game loop, a scoring system, and a high-score table. Design a
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