Specification and programming interface #
Specification #
The specification of a method primarily describes the problem that the method solves (i.e. its input and expected output).
Optionally, the specification may provide information about:
- the behavior of the program for invalid inputs (e.g. errors thrown by the method),
- its implementation (if this has an impact on performance ),
- etc.
Example.
boolean isSolvable(int[][] grid)
- Input: a 9 x 9 array of integers with numbers between 0 and 9
- Output: true is this array represents a sudoku grid with a unique solution (where 0 stands for the absence of value)
- Errors:
- if the array’s size is not 9 x 9
- if the array contains a number smaller that 0 or greater than 9
Variation. If a method has no return type or is not a pure function, then the specification may indicate the effect of the method on its environment.
Variation. The specification of a command (for a CLI) is similar, but may include additional information about the syntax of the command (options, arguments, etc.)
Programming interface #
In its simplest form, a programming interface is a set of method/command specifications.