<s>
Design	B-Application
by	I-Application
contract	I-Application
(	O
DbC	B-Application
)	O
,	O
also	O
known	O
as	O
contract	B-Application
programming	I-Application
,	O
programming	B-Application
by	I-Application
contract	I-Application
and	O
design-by-contract	O
programming	O
,	O
is	O
an	O
approach	O
for	O
designing	O
software	O
.	O
</s>
<s>
It	O
prescribes	O
that	O
software	O
designers	O
should	O
define	O
formal	B-Architecture
,	O
precise	O
and	O
verifiable	O
interface	O
specifications	B-Application
for	O
software	B-Architecture
components	I-Architecture
,	O
which	O
extend	O
the	O
ordinary	O
definition	O
of	O
abstract	O
data	O
types	O
with	O
preconditions	O
,	O
postconditions	O
and	O
invariants	B-Application
.	O
</s>
<s>
These	O
specifications	B-Application
are	O
referred	O
to	O
as	O
"	O
contracts	O
"	O
,	O
in	O
accordance	O
with	O
a	O
conceptual	O
metaphor	O
with	O
the	O
conditions	O
and	O
obligations	O
of	O
business	O
contracts	O
.	O
</s>
<s>
The	O
DbC	B-Application
approach	O
assumes	O
all	O
client	O
components	O
that	O
invoke	O
an	O
operation	O
on	O
a	O
server	O
component	O
will	O
meet	O
the	O
preconditions	O
specified	O
as	O
required	O
for	O
that	O
operation	O
.	O
</s>
<s>
Where	O
this	O
assumption	O
is	O
considered	O
too	O
risky	O
(	O
as	O
in	O
multi-channel	O
or	O
distributed	B-Architecture
computing	I-Architecture
)	O
,	O
the	O
inverse	O
approach	O
is	O
taken	O
,	O
meaning	O
that	O
the	O
server	O
component	O
tests	O
that	O
all	O
relevant	O
preconditions	O
hold	O
true	O
(	O
before	O
,	O
or	O
while	O
,	O
processing	O
the	O
client	O
components	O
request	O
)	O
and	O
replies	O
with	O
a	O
suitable	O
error	O
message	O
if	O
not	O
.	O
</s>
<s>
The	O
term	O
was	O
coined	O
by	O
Bertrand	O
Meyer	O
in	O
connection	O
with	O
his	O
design	O
of	O
the	O
Eiffel	B-Language
programming	I-Language
language	I-Language
and	O
first	O
described	O
in	O
various	O
articles	O
starting	O
in	O
1986Meyer	O
,	O
Bertrand	O
:	O
Design	B-Application
by	I-Application
Contract	I-Application
,	O
Technical	O
Report	O
TR-EI-12/CO	O
,	O
Interactive	O
Software	O
Engineering	O
Inc.	O
,	O
1986Meyer	O
,	O
Bertrand	O
:	O
Design	B-Application
by	I-Application
Contract	I-Application
,	O
in	O
Advances	O
in	O
Object-Oriented	B-Language
Software	I-Language
Engineering	I-Language
,	O
eds	O
.	O
</s>
<s>
D	B-Application
.	O
Mandrioli	O
and	O
B	O
.	O
Meyer	O
,	O
Prentice	O
Hall	O
,	O
1991	O
,	O
pp	O
.	O
</s>
<s>
1	O
–	O
50Meyer	O
,	O
Bertrand	O
:	O
Applying	O
"	O
Design	B-Application
by	I-Application
Contract	I-Application
"	O
,	O
in	O
Computer	O
(	O
IEEE	O
)	O
,	O
25	O
,	O
10	O
,	O
October	O
1992	O
,	O
pp	O
.	O
</s>
<s>
40	O
–	O
51	O
,	O
also	O
available	O
online	O
and	O
the	O
two	O
successive	O
editions	O
(	O
1988	O
,	O
1997	O
)	O
of	O
his	O
book	O
Object-Oriented	B-Language
Software	O
Construction	O
.	O
</s>
<s>
Eiffel	B-Language
Software	O
applied	O
for	O
trademark	O
registration	O
for	O
Design	B-Application
by	I-Application
Contract	I-Application
in	O
December	O
2003	O
,	O
and	O
it	O
was	O
granted	O
in	O
December	O
2004	O
.	O
</s>
<s>
The	O
current	O
owner	O
of	O
this	O
trademark	O
is	O
Eiffel	B-Language
Software	O
.	O
</s>
<s>
Design	B-Application
by	I-Application
contract	I-Application
has	O
its	O
roots	O
in	O
work	O
on	O
formal	B-Architecture
verification	O
,	O
formal	B-Application
specification	I-Application
and	O
Hoare	O
logic	O
.	O
</s>
<s>
The	O
central	O
idea	O
of	O
DbC	B-Application
is	O
a	O
metaphor	O
on	O
how	O
elements	O
of	O
a	O
software	O
system	O
collaborate	O
with	O
each	O
other	O
on	O
the	O
basis	O
of	O
mutual	O
obligations	O
and	O
benefits	O
.	O
</s>
<s>
Similarly	O
,	O
if	O
the	O
method	O
of	O
a	O
class	O
in	O
object-oriented	B-Language
programming	I-Language
provides	O
a	O
certain	O
functionality	O
,	O
it	O
may	O
:	O
</s>
<s>
Expect	O
a	O
certain	O
condition	O
to	O
be	O
guaranteed	O
on	O
entry	O
by	O
any	O
client	O
module	B-Architecture
that	O
calls	O
it	O
:	O
the	O
method	O
's	O
precondition	O
—	O
an	O
obligation	O
for	O
the	O
client	O
,	O
and	O
a	O
benefit	O
for	O
the	O
supplier	O
(	O
the	O
method	O
itself	O
)	O
,	O
as	O
it	O
frees	O
it	O
from	O
having	O
to	O
handle	O
cases	O
outside	O
of	O
the	O
precondition	O
.	O
</s>
<s>
Maintain	O
a	O
certain	O
property	O
,	O
assumed	O
on	O
entry	O
and	O
guaranteed	O
on	O
exit	O
:	O
the	O
class	B-Application
invariant	I-Application
.	O
</s>
<s>
However	O
,	O
DbC	B-Application
considers	O
these	O
contracts	O
to	O
be	O
so	O
crucial	O
to	O
software	O
correctness	O
that	O
they	O
should	O
be	O
part	O
of	O
the	O
design	O
process	O
.	O
</s>
<s>
In	O
effect	O
,	O
DbC	B-Application
advocates	O
writing	O
the	O
assertions	O
first	O
.	O
</s>
<s>
Subclasses	O
in	O
an	O
inheritance	B-Language
hierarchy	I-Language
are	O
allowed	O
to	O
weaken	O
preconditions	O
(	O
but	O
not	O
strengthen	O
them	O
)	O
and	O
strengthen	O
postconditions	O
and	O
invariants	B-Application
(	O
but	O
not	O
weaken	O
them	O
)	O
.	O
</s>
<s>
These	O
rules	O
approximate	O
behavioural	B-Application
subtyping	I-Application
.	O
</s>
<s>
Other	O
design	O
contracts	O
are	O
concepts	O
of	O
class	B-Application
invariant	I-Application
.	O
</s>
<s>
The	O
class	B-Application
invariant	I-Application
guarantees	O
(	O
for	O
the	O
local	O
class	O
)	O
that	O
the	O
state	O
of	O
the	O
class	O
will	O
be	O
maintained	O
within	O
specified	O
tolerances	O
at	O
the	O
end	O
of	O
each	O
feature	O
execution	O
.	O
</s>
<s>
When	O
using	O
contracts	O
,	O
a	O
supplier	O
should	O
not	O
try	O
to	O
verify	O
that	O
the	O
contract	O
conditions	O
are	O
satisfied	O
—	O
a	O
practice	O
known	O
as	O
offensive	B-Application
programming	I-Application
—	O
the	O
general	O
idea	O
being	O
that	O
code	O
should	O
"	O
fail	O
hard	O
"	O
,	O
with	O
contract	O
verification	O
being	O
the	O
safety	O
net	O
.	O
</s>
<s>
DbC	B-Application
's	O
"	O
fail	O
hard	O
"	O
property	O
simplifies	O
the	O
debugging	O
of	O
contract	O
behavior	O
,	O
as	O
the	O
intended	O
behaviour	O
of	O
each	O
method	O
is	O
clearly	O
specified	O
.	O
</s>
<s>
This	O
approach	O
differs	O
substantially	O
from	O
that	O
of	O
defensive	B-Application
programming	I-Application
,	O
where	O
the	O
supplier	O
is	O
responsible	O
for	O
figuring	O
out	O
what	O
to	O
do	O
when	O
a	O
precondition	O
is	O
broken	O
.	O
</s>
<s>
More	O
often	O
than	O
not	O
,	O
the	O
supplier	O
throws	O
an	O
exception	B-General_Concept
to	O
inform	O
the	O
client	O
that	O
the	O
precondition	O
has	O
been	O
broken	O
,	O
and	O
in	O
both	O
cases	O
—	O
DbC	B-Application
and	O
defensive	B-Application
programming	I-Application
alike	O
—	O
the	O
client	O
must	O
figure	O
out	O
how	O
to	O
respond	O
to	O
that	O
.	O
</s>
<s>
In	O
such	O
cases	O
,	O
DbC	B-Application
makes	O
the	O
supplier	O
's	O
job	O
easier	O
.	O
</s>
<s>
Design	B-Application
by	I-Application
contract	I-Application
also	O
defines	O
criteria	O
for	O
correctness	O
for	O
a	O
software	O
module	B-Architecture
:	O
</s>
<s>
If	O
the	O
class	B-Application
invariant	I-Application
AND	O
precondition	O
are	O
true	O
before	O
a	O
supplier	O
is	O
called	O
by	O
a	O
client	O
,	O
then	O
the	O
invariant	B-Application
AND	O
the	O
postcondition	O
will	O
be	O
true	O
after	O
the	O
service	O
has	O
been	O
completed	O
.	O
</s>
<s>
When	O
making	O
calls	O
to	O
a	O
supplier	O
,	O
a	O
software	O
module	B-Architecture
should	O
not	O
violate	O
the	O
supplier	O
's	O
preconditions	O
.	O
</s>
<s>
Design	B-Application
by	I-Application
contract	I-Application
can	O
also	O
facilitate	O
code	O
reuse	O
,	O
since	O
the	O
contract	O
for	O
each	O
piece	O
of	O
code	O
is	O
fully	O
documented	O
.	O
</s>
<s>
The	O
contracts	O
for	O
a	O
module	B-Architecture
can	O
be	O
regarded	O
as	O
a	O
form	O
of	O
software	O
documentation	O
for	O
the	O
behavior	O
of	O
that	O
module	B-Architecture
.	O
</s>
<s>
Asserts	O
are	O
by	O
default	O
compiled	O
away	O
in	O
release	O
mode	O
in	O
C/C	O
++	O
,	O
and	O
similarly	O
deactivated	O
in	O
C#	B-Application
and	O
Java	B-Language
.	O
</s>
<s>
Design	B-Application
by	I-Application
contract	I-Application
does	O
not	O
replace	O
regular	O
testing	O
strategies	O
,	O
such	O
as	O
unit	O
testing	O
,	O
integration	O
testing	O
and	O
system	O
testing	O
.	O
</s>
<s>
The	O
use	O
of	O
assertions	O
can	O
be	O
considered	O
to	O
be	O
a	O
form	O
of	O
test	B-Application
oracle	I-Application
,	O
a	O
way	O
of	O
testing	O
the	O
design	B-Application
by	I-Application
contract	I-Application
implementation	O
.	O
</s>
<s>
Languages	O
that	O
implement	O
most	O
DbC	B-Application
features	O
natively	O
include	O
:	O
</s>
<s>
Additionally	O
,	O
the	O
standard	O
method	O
combination	O
in	O
the	O
Common	B-Application
Lisp	I-Application
Object	I-Application
System	I-Application
has	O
the	O
method	O
qualifiers	O
:before	O
,	O
:after	O
and	O
:around	O
that	O
allow	O
writing	O
contracts	O
as	O
auxiliary	O
methods	O
,	O
among	O
other	O
uses	O
.	O
</s>
<s>
Various	O
libraries	O
,	O
preprocessors	B-General_Concept
and	O
other	O
tools	O
have	O
been	O
developed	O
for	O
existing	O
programming	O
languages	O
without	O
native	O
design	B-Application
by	I-Application
contract	I-Application
support	O
:	O
</s>
<s>
Ada	B-Language
,	O
via	O
GNAT	B-Language
pragmas	O
for	O
preconditions	O
and	O
postconditions	O
.	O
</s>
<s>
C	B-Language
and	O
C++	B-Language
:	O
</s>
<s>
Loki	B-Language
Library	I-Language
provides	O
a	O
mechanism	O
named	O
ContractChecker	O
that	O
verifies	O
a	O
class	O
follows	O
design	B-Application
by	I-Application
contract	I-Application
.	O
</s>
<s>
Java	B-Language
:	O
</s>
<s>
JavaScript	B-Language
,	O
via	O
decorator-contracts	O
,	O
AspectJS	B-Application
(	O
specifically	O
,	O
AJS_Validator	O
)	O
,	O
Cerny.js	O
,	O
ecmaDebug	O
,	O
jsContract	O
,	O
dbc-code-contracts	O
or	O
jscategory	O
.	O
</s>
<s>
Common	B-Language
Lisp	I-Language
,	O
via	O
the	O
macro	O
facility	O
or	O
the	O
CLOS	B-Application
metaobject	O
protocol	O
.	O
</s>
<s>
Nemerle	B-Application
,	O
via	O
macros	O
.	O
</s>
<s>
Nim	B-Application
,	O
via	O
macros	O
.	O
</s>
<s>
Perl	B-Language
,	O
via	O
the	O
CPAN	B-Language
modules	B-Architecture
Class::Contract	O
(	O
by	O
Damian	O
Conway	O
)	O
or	O
Carp::Datum	O
(	O
by	O
Raphael	O
Manfredi	O
)	O
.	O
</s>
<s>
PHP	B-Application
,	O
via	O
PhpDeal	O
,	O
Praspel	B-Language
or	O
Stuart	O
Herbert	O
's	O
ContractLib	O
.	O
</s>
<s>
Python	B-Language
,	O
using	O
packages	O
like	O
deal	O
,	O
icontract	O
,	O
PyContracts	O
,	O
dpcontracts	O
,	O
or	O
zope.interface	O
.	O
</s>
<s>
A	O
permanent	O
change	O
to	O
Python	B-Language
to	O
support	O
design	O
by	O
contracts	O
was	O
proposed	O
in	O
PEP-316	O
in	O
2003	O
,	O
but	O
is	O
deferred	O
.	O
</s>
<s>
Ruby	B-Language
,	O
via	O
Brian	O
McCallister	O
's	O
DesignByContract	O
,	O
Ruby	B-Language
DBC	B-Application
ruby-contract	O
or	O
contracts.ruby	O
.	O
</s>
<s>
Rust	B-Application
via	O
the	O
contracts	O
crate	O
.	O
</s>
<s>
Swift	B-Application
via	O
the	O
cocoapod	O
by	O
Jim	O
Boyd	O
.	O
</s>
<s>
Tcl	B-Operating_System
,	O
via	O
the	O
XOTcl	B-Language
object-oriented	B-Language
extension	O
.	O
</s>
<s>
A	O
wikibook	O
describing	O
DBC	B-Application
closely	O
to	O
the	O
original	O
model	O
.	O
</s>
<s>
This	O
paper	O
discusses	O
generalized	O
notions	O
of	O
Contract	O
and	O
Substitutability	B-Application
 '	O
.	O
</s>
