Specification and programming interface

Specification and programming interface #

Specification #

The specification of a method usually consists of:

  • the computational problem that the method solves (if any), and
  • (if needed,) a description of the format of the input and expected output, and
  • (if applicable,) a description of the behavior of the program for invalid inputs (e.g. errors thrown by the method), and
  • (if useful,) information about the implementation (e.g. if this may have an impact on performance for certain inputs).

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

If a method has no return type or is not a pure function, then the specification may indicate the effect the method on its environment.

The specification of a command (for a program with a command line interface) 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.