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 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
easy
A student writes a 200-line program as one big block of code. Suggest how they could improve it using modular design.
Answer
Break the program into separate functions for each task. Each function handles one responsibility and can be tested independently.
First step
1
Step 1: Identify distinct tasks in the program (e.g., reading input, processing data, displaying results).
Full solution
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.
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.
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.
Example 3
medium
A chat app has: connection handler, message parser, UI renderer, notification system. Suggest a 4-module split and one interface each module exposes.
Example 4
medium
A team of 3 developers must build an online quiz: auth, question bank, scoring. Which modular split lets the 3 work in parallel with minimal blocking?
Example 5
medium
Code review flags a 700-line file containing login, password reset, and audit logging. Suggest a refactor and how many modules result.
Example 6
hard
A 4-module system has cyclic dependencies: A->B->C->D->A. Why is this risky, and propose a fix.
Example 7
hard
A team wants to replace its REST API client with a GraphQL client. The app has 40 call sites. Sketch the modular approach that minimizes call-site changes.
Example 8
challenge
Design a 5-module split for a streaming music service: playback, library, recommendations, billing, auth. State each interface and one cross-module call.
Practice Problems
Try these problems on your own first, then open the solution to compare your method.
Example 1
medium
List three benefits of modular design and give a specific example of each benefit in the context of a team building a web application.
Example 2
hard
Explain the concepts of coupling and cohesion in modular design. Why do we want low coupling and high cohesion? Give an example of a poor design that violates these principles.
Example 3
easy
Structuring a program as independent self-contained units each doing one task is called ____ design.
Example 4
easy
A module should ideally do how many well-defined tasks?
Example 5
easy
Modules communicate through clear ____ rather than touching each other's internals.
Example 6
easy
Two modules that depend heavily on each other's internal details are said to be tightly ____.
Example 7
easy
Can a well-designed module be replaced without rewriting the rest of the system, if its interface stays the same?
Example 8
easy
A system built from modules M1β,M2β,M3β has how many modules?
Example 9
easy
Designing modules so each can be tested on its own supports what activity?
Example 10
easy
The LEGO-block analogy for modular design emphasizes that each block does what?
Example 11
medium
A program has functions: read input, validate, compute, format output. Roughly how many modules suggest good separation here?
Example 12
medium
Module A calls Module B through a 3-function interface but also reads B's internal variable. Is coupling tight or loose, and why?
Example 13
medium
A 500-line module handles login, logging, and email. Which design principle does it violate?
Example 14
medium
If you change a function's internal algorithm but keep its inputs and outputs identical, must callers change?
Example 15
medium
A system has modules that all directly call each other (full mesh) of 5 modules. How many directed dependency pairs is that, and is that desirable?
Example 16
medium
Why does modular design make debugging faster?
Example 17
medium
A weather app reuses one 'unit converter' module in 6 places. What benefit of modular design does this show?
Example 18
medium
A program has 3 modules, and you need to fix a bug isolated to module 2. With loose coupling, how many modules should you need to edit?
Example 19
medium
Module A and Module B both need a date-formatting routine. What does modular design recommend instead of duplicating the code?
Example 20
challenge
You must add a new payment method. With high cohesion and loose coupling, what is the ideal scope of code change, and why?
Example 21
challenge
Two modules share a global mutable variable to communicate. Explain why this is worse than passing data through an interface, in coupling terms.
Example 22
challenge
Design: a media player must support audio and video, sharing playback controls but differing in decoding. Sketch a module split that maximizes cohesion and minimizes coupling.
Example 23
easy
True or false: a module that does one well-defined task is said to have high cohesion.
Example 24
easy
A system has modules M1β,M2β,β¦,M7β. How many modules in total?
Example 25
easy
A 'Utilities' module contains string helpers, math helpers, file helpers, and email helpers. Is its cohesion high or low?
Example 26
easy
Which is preferred in modular design: high cohesion + loose coupling, or low cohesion + tight coupling?
Example 27
medium
A program has 6 modules in a full mesh (every module calls every other). How many directed call pairs is that?
Example 28
medium
Module A imports 12 internal symbols from Module B. Module C imports only 1 function from B. Which pair (A-B or C-B) is more loosely coupled?
Example 29
medium
You want to replace the storage backend (file vs SQL) without touching the rest of the app. Which design pattern supports this?
Example 30
medium
True or false: changing the internal data structure inside a module forces every caller to change, even if the interface is unchanged.
Example 31
medium
A program duplicates the same 30-line date-parsing block in 5 places. According to modular design, what should you do?
Example 32
medium
Eight teams each own one module, and any module that changes can require rebuilding every dependent module. If 8 modules form a full directed mesh, how many dependency edges are there?
Example 33
medium
A library exposes 30 public functions but uses 200 private ones internally. The 30 public ones form what?
Example 34
hard
A program has 10 modules. After a refactor, dependency edges drop from 45 to 12. Describe what likely changed and why it matters.
Example 35
hard
Two modules communicate by writing to a shared file with no defined format. Identify the coupling type and a safer alternative.
Example 36
hard
You need to add logging across 15 modules without touching their core logic. Which modular technique fits best: shared singleton import, or inject a logger via the interface?
Example 37
hard
A system has k modules. As k grows, what bounds the worst-case number of pairwise interactions, and why does this push designs toward layering?
Example 38
challenge
A monolith of 100,000 lines is split into 20 modules of about 5,000 lines each, with average dependency degree 3. Estimate edges and contrast with full mesh.