Interface Formula
A software interface is the visible contract that tells other parts of a program how to interact with a module, function, or system.
The Formula
Ask yourself: Does one part of a program use another only through the inputs, outputs and rules it publishes, without seeing inside?
Quick example
What this formula means
A software interface is the visible contract that tells other parts of a program how to interact with a module, function, or system. It defines the inputs, outputs, and rules of use without exposing the internal implementation.
An interface works like a restaurant menu: it lists what you can order and what will arrive, and you never see the kitchen. The chef can change the oven or the recipe and your order still comes as described. Change the menu itself, though, and regulars who order their usual dish are suddenly stuck.
Formal view
Worked examples
Example 1
easyShow solution
Answer
First step
See the full worked solution + why-it-works coaching
SetupKey insightWhy it worksCommon pitfallConnection
Example 2
mediumExample 3
mediumCommon mistakes
- Exposing internal details that other modules should not depend on
- Changing an interface without updating the code that depends on it
- Leaving inputs or error cases unspecified so the contract is ambiguous
Why this formula matters
Interfaces are what let five people build one app: each person codes behind an agreed interface, and the pieces fit at the end. They also make change safe, because a slow function can be swapped for a fast one that accepts and returns the same things. When an interface is vague or exposes internal details, a change inside one module can break code elsewhere that nobody remembered depended on it.
Frequently asked questions
What is the Interface formula?
A software interface is the visible contract that tells other parts of a program how to interact with a module, function, or system. It defines the inputs, outputs, and rules of use without exposing the internal implementation.
How do you use the Interface formula?
Look at the interface when a problem asks how two modules or functions connect, what a function takes and returns, what a caller may rely on, or what breaks when a function's inputs change. Clues: parameters, return values, an API, 'other code calls this'. If the question is about buttons and screens a person uses, think User Interface; if it is about splitting a program into parts in the first place, that is modular design; checking the promised behaviour is Unit Testing.
Why is the Interface formula important in CS Thinking?
Interfaces are what let five people build one app: each person codes behind an agreed interface, and the pieces fit at the end. They also make change safe, because a slow function can be swapped for a fast one that accepts and returns the same things. When an interface is vague or exposes internal details, a change inside one module can break code elsewhere that nobody remembered depended on it.
What do students get wrong about Interface?
An interface describes what a module does and how to use it, not how it is implemented internally.
What should I learn before the Interface formula?
Before studying the Interface formula, you should understand: modular design.