11.7. Guideline: When Are Contracts Useful?
In the UP, the use cases are the main repository of requirements for the project. They may provide most or all of the detail necessary to know what to do in the design, in which case, contracts are not helpful. However, there are situations where the details and complexity of required state changes are awkward or too detailed to capture in use cases.For example, consider an airline reservation system and the system operation addNewReservation . The complexity is very high regarding all the domain objects that must be changed, created, and associated. These fine-grained details can be written up in the use case, but it will make it extremely detailed (for example, noting each attribute in all the objects that must change).Observe that the postcondition format offers and encourages a very precise, analytical language that supports detailed thoroughness.If developers can comfortably understand what to do without them, then avoid writing contracts.This case study shows more contracts than are necessaryfor education. In practice, most of the details they record are obviously inferable from the use case text. On the other hand, "obvious" is a slippery concept!