Interfaces, Coupling and What a Module Promises
A module's interface is the set of promises other code may rely on, and everything else is free to change. Coupling measures how much of a neighbour's insides a caller depends on, and it is the quantity that decides how expensive the next change will be.
What a learner can do afterwards
- State the promise of a module without describing how it is implemented
- Find the place where one module reaches past another's interface
- Predict which of two designs makes a stated future change cheaper
1 · Read
A module interface is the set of promises other code may rely on: named functions and constants it offers. Everything else is free to change, and that freedom is what keeps later edits cheap.
A module that prints messages or changes files just because you imported it has broken its promise. The fix is a guard: put run only code inside if __name__ equals __main__, so importing gives exactly the published names and nothing more.
How you import decides how much of a neighbor you lean on. Writing import shapes and then shapes.Circle keeps the home visible, while from shapes import Circle ties you to that exact name. An alias like import shapes as sh shortens typing without hiding where things live. In each style you should rest only on names the module chose to publish.
Coupling measures how much of a neighbor insides a caller depends on. Code that reaches past the published surface feels any internal reorganization, so the design that stays on the surface makes the next change cheaper.
Rest only on published names, guard run only code, and the module inside stays free to change.
2 · Watch
Take it off screen
Where it sits
8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.