Contract-Oriented Programming
Overview
Contract-oriented programming is a software development paradigm in which software components are described alongside explicit contracts that specify the obligations and benefits of interacting with them. These contracts typically define preconditions, postconditions, and invariants that govern the behavior of operations, allowing implementations and their specifications to be reasoned about in a unified framework.
Specification Languages Built on Contracts
Research in automated software engineering has explored using contract-oriented programming as a basis for formal specification languages. By extending the core idea of contracts with additional structuring concepts, these languages can express richer behavioral properties of software.
Extension with Finite State Machines
One notable extension combines the contract-oriented paradigm with finite state machines. This produces a specification language in which:
- Each component is described by a set of contracts (pre/post-condition style specifications).
- The dynamic behavior of the component is captured by a finite state machine that constrains the legal sequences of operations.
- The combination enables symbolic reasoning about both individual method calls and full interaction scenarios.
This style of specification has been used as input to automated test case generation, where the goal is not only to produce valid arguments for individual methods but also to generate complete execution scenarios that respect the underlying state machine.
Applications
The primary application documented in the literature is automated testing:
- Constraint-based test generation. Specifications written in a contract-oriented language extended with finite state machines can be animated symbolically, producing test cases and scenarios that satisfy the encoded constraints.
- Full scenario synthesis. Beyond generating individual method arguments, the symbolic animation of the specification can produce complete sequences of calls that exercise realistic interaction paths through the finite state machine.
- Flexible constraint solving. The approach supports constraint solving over integer and bounded domains as well as over arbitrary types, using mechanisms such as type builders to connect application-level type semantics with the underlying constraint satisfaction framework.
Related Concepts
- Specification language. Contract-oriented programming has been used as the conceptual foundation upon which specification languages are constructed, particularly those that extend it with further constructs such as finite state machines for behavioral modeling.
See Also
References
- Trabelsi, A., et al. A Constraint Logic Programming Approach to Automated Testing. In: Proceedings of the 20th International Conference on Logic Programming (ICLP 2004), Saint-Malo, France. Springer, 2004.