www.digitalmars.com         C & C++   DMDScript  

D - Why must "only one" of a base function's precondition be satisfied?

reply samoconnor mac.com writes:
From: http://www.digitalmars.com/d/dbc.html

 In, Out and Inheritance
 If a function in a derived class overrides a function in its  super class,
 then only one of  the in contracts of the base functions must be satisified
 Overriding  functions then becomes a process of loosening the in  contracts.

In OOSC2 (P573) Meyer (who invented Design by Contract) says:
 Assertion Redeclaration rule
 A routine redeclreation may only replace the original precondition
 by one equal or weaker, and the original postcondition by one equal or
storgner.

I am intersted to know why in D, "one of the in contracts of the base functions must be specified". Why must any of the "contracts of the base functions" be satisifed at all if the new precondition is satisfied. If an overriden function has a new precondition it should be or-ed with the existing preconditions. Is this the intention in D? Sam O'Connor
Apr 19 2004
parent "Walter" <newshound digitalmars.com> writes:
<samoconnor mac.com> wrote in message
news:c600ck$203e$1 digitaldaemon.com...
 From: http://www.digitalmars.com/d/dbc.html

 In, Out and Inheritance
 If a function in a derived class overrides a function in its  super


 then only one of  the in contracts of the base functions must be


 Overriding  functions then becomes a process of loosening the in


 In OOSC2 (P573) Meyer (who invented Design by Contract) says:

 Assertion Redeclaration rule
 A routine redeclreation may only replace the original precondition
 by one equal or weaker, and the original postcondition by one equal or


 I am intersted to know why in D, "one of the in contracts of the base

 must
 be specified". Why must any of the "contracts of the base functions" be
 satisifed at
 all if the new precondition is satisfied.
 If an overriden function has a new precondition it should be or-ed with
 the existing preconditions. Is this the intention in D?

Yes, or-ing the preconditions is the same thing as stating that any of the preconditions need to be satisified, which is the same thing as what Meyer writes.
May 26 2004