Lecture 6 min.
Contract programming ( design by contract (DbC), programming by contract , contract-based programming ) is a software design method. He suggests that the designer should define formal, accurate, and verifiable interface specifications for system components. In addition to the usual definition of abstract data types, preconditions , postconditions and invariants are also used. These specifications are called "contracts" in accordance with the conceptual metaphor of conditions and liability in civil law contracts.
The term suggested by Bertrand Meyer in connection with the development of the Eiffel language. Contract programming has grown out of formal verification, formal specification and Hoare logic. Contract programming is not only a simple metaphor that indicates a design method. Conditions facilitating the use of contract programming:

rice contract module design
The main idea of contract programming is a model of interaction of elements of a software system based on the idea of mutual obligations and benefits . As in business, the customer and the supplier act in accordance with a specific contract . A contract of a certain method or function may include:
Many programming languages allow for such commitments. Contract programming implies these requirements are critical to the correctness of programs, so they must be approved during design. Thus, contract programming prescribes starting to write code with writing formal assertions of correctness (assertions).
In object-oriented programming, a method contract usually includes the following information:
When using contracts, the code itself is not obliged to verify their implementation. Usually in such cases, the code makes a hard drop [ clarify ] (“ fail-fast ”), thus facilitating the debugging of the execution of contracts. In many languages, such as C, C ++, Delphi, PHP, this behavior is implemented by the assert operator. In the release version of the code, this behavior can be saved, or checks can be removed to improve performance.
Unit tests check the module in isolation from others, checking that the module meets the assumptions of the contract, and also the modules used by it fulfill their contracts. Integration tests verify that the modules work correctly together.
Contract programming can increase code reuse as the module’s commitments are clearly documented. In general, a module contract can also be viewed as a software documentation method.
Languages that initially support tools for contract programming:
Sign in and the lectures you have studied will be marked in this list.
Choose a course
Comments