Design by contract can be seen as an advanced software engineering technique for building quality software in a professional environment or as a fundamental programming concept, useful even for elementary programming. If design by contract is an afterthought, sophisticated tool support, with macros, preprocessors or patterns is acceptable. If it is to be used from the very first programs, it must not be yet another difficult obstacle to the novice programmer. This point of view seems to recommend Eiffel as the sole vehicle for the early introduction of design by contract. However, compromises are possible, if your organization mandates C++, for example. For design by contract in C++ we use a class template, Assertions , which is inherited by the classes we are specifying. This class handles preconditions, postconditions and class invariants, and supports the "old" notation. The assertions themselves are not difficult to implement but the "old" notation, which is necessary in order to compare the value of an attribute in a postcondition with its value at an earlier stage in the function, raises interesting issues. In most common situations, using the assertions is straightforward. There are, however, more rare cases involving inheritance and recursion that must be handled with a discipline.
[1]
Ernesto Pimentel,et al.
Eiffel-like Assertions and Private Methods in Smalltalk
,
1994,
TOOLS.
[2]
Bjarne Stroustrup,et al.
The Design and Evolution of C
,
1994
.
[3]
Reinhold Plösch,et al.
Tool Support for Design by Contract
,
1998,
TOOLS.
[4]
David R. Musser,et al.
STL tutorial and reference guide
,
2001
.
[5]
Jean-Marc Jézéquel,et al.
Design by Contract: The Lessons of Ariane
,
1997,
Computer.
[6]
W. T. Singleton,et al.
Man-machine systems
,
1974
.
[7]
John L. Bruno,et al.
jContractor: A Reflective Java Library to Support Design by Contract
,
1999,
Reflection.
[8]
R. Kramer.
iContract - The Java(tm) Design by Contract(tm) Tool
,
1998
.
[9]
Bertrand Meyer,et al.
Object-Oriented Software Construction, 2nd Edition
,
1997
.
[10]
Pedro Guerreiro.
Another mediocre assertion mechanism for C++
,
2000,
Proceedings 33rd International Conference on Technology of Object-Oriented Languages and Systems TOOLS 33.