Modular Design Examples in CS Thinking
Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Modular Design.
This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.
Concept Recap
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.
LEGO blocksβeach piece does one thing and connects to others in standard ways.
Read the full concept explanation βHow to Use These Examples
- Read the first worked example with the solution open so the structure is clear.
- Try the practice problems before revealing each solution.
- Use the related concepts and background knowledge badges if you feel stuck.
What to Focus On
Core idea: Modules can be developed, tested, and replaced independently.
Common stuck point: Modules should have minimal dependencies on each other (loose coupling).
Sense of Study hint: When applying modular design, first identify the distinct responsibilities in your program (e.g., input handling, data processing, display). Then create a separate module for each responsibility with a clear interface. Finally, ensure modules communicate only through their interfaces, not by accessing each other's internal data.
Worked Examples
Example 1
easySolution
- 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
Example 2
mediumPractice Problems
Try these problems on your own first, then open the solution to compare your method.
Example 1
mediumExample 2
hardRelated Concepts
Background Knowledge
These ideas may be useful before you work through the harder examples.