Operating contracts specify how a function will change elements in a program. They define the name of the operation, references, input requirements, and the state of the system after the operation. They are used for complex operations and define preconditions and post-conditions. They help visualize how a program can change and shape it before implementation.
In the field of computer programming and computer science, operating contracts are a way of specifying or documenting how a particular function will change different elements within a program. Unlike an abstract programming interface (API) or interface control document, operating contracts are used to assist during the development and modeling phase of building an application or computer system. At the most basic level, the contract defines four characteristics of the operation, namely the name of the operation, any references to the operation in other areas of the project, any input requirements or status before the operation is performed, and the state of the system or variables after the operation has been performed. The contract doesn’t define anything specific about how the operation works internally, and instead deals only with how the state of a program is affected by its use.
Operation contracts, in general, are not built for every operation within a program template. Instead, they are reserved for operations that are particularly complex or difficult to trace. Several computer modeling languages, such as the Unified Modeling Language (UML), support operating contracts and have ways to help visualize how the state of a program can change once the operation has been performed.
The first two definitions required to create operation contracts are the name of the operation, which can be anything, and any cross-references. A cross reference is a list of other operations or areas of a program template that use the defined operation or that the operation will use in its processing. This helps to see how an overall project interacts, and is particularly useful for seeing how changes to one area of the model will affect other areas.
The operation contracts therefore define the preconditions necessary to carry out the operation. This may involve a requirement to load certain variables with appropriate values, or it may require certain parts of the program to be in a particular state. If the preconditions are not met when the operation runs, the operation will not take place or may fail completely. The contract is used as an abstract tool, so the preconditions are usually quite general and involve more the state of the program than specific variables.
The final part of the operational contracts defines any post-conditions. Postconditions are a list of elements within the program template that have changed due to the execution of the operation. This can specify changes to a data structure or program state changes, such as moving the control to a separate form. Through the use of well-defined operating contracts, programs can be effectively shaped and modified before actual implementation begins.
Protect your devices with Threat Protection by NordVPN