Authors:
Sérgio Agostinho
1
;
Pedro Guerreiro
2
and
Hugo Taborda
1
Affiliations:
1
Universidade Nova de Lisboa, Portugal
;
2
Universidade do Algarve, Portugal
Abstract:
Several techniques exist for introducing Design by Contract in languages providing no direct support for it, such as Java. One such technique uses aspects that introduce preconditions and postconditions by means of before and after advices. For using this, programmers must be knowledgeable of the aspect language, even if they would rather concentrate on Design by Contract alone. On the other hand, we can use aspects to weave in preconditions, preconditions and invariants that have been programmed in the source language, as regular Boolean functions. In doing this, we must find ways to automatically “inherit” preconditions and postconditions when redefining functions in subclasses and we must be able to record the initial state of the object when calling a modifier, so that it can be observed in the postconditions. With such a system, during development, the program will be compiled together with the aspects providing the Design by Contract facilities, using the compiler for the aspec
t language, and the running program will automatically check all the weaved in assertions, raising an exception when they evaluate to false. For the release build, it suffices to compile using the source language compiler, ignoring the aspects, and the assertions will be left out.
(More)