Learning path

Full curriculum

Full curriculum

Unit content

Program decomposition and modules

As a program grows, understanding everything at once becomes difficult. Decomposition divides the program into parts with clear responsibilities and interfaces.

Functions as boundaries

A function hides a piece of implementation behind a name, parameters and a return value. Callers need to know the function's contract rather than every internal step.

Modules

A module groups related definitions into a larger unit. A module may expose some names as its public interface while keeping other details internal.

For example, a module for temperatures might expose conversion functions while hiding constants and helper functions used to implement them.

Dependencies

One module can depend on another through imports or similar language mechanisms. Keeping dependencies explicit makes it easier to see which parts of the program rely on which others.

Cohesion and coupling

A well-focused module groups things that belong together: it has high cohesion.

Modules should also avoid unnecessary knowledge of one another's internal details: lower coupling makes changes less likely to spread across the whole system.

Decomposition is therefore not merely splitting a large file into smaller files. It is choosing boundaries that let each part be understood, tested and changed with as little knowledge of the rest as practical.