[Issue 6857] Precondition contract checks should be statically bound.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu May 3 01:42:31 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6857
--- Comment #12 from deadalnix <deadalnix at gmail.com> 2012-05-03 01:43:42 PDT ---
(In reply to comment #11)
> >The current specification is flawed. It have nothing to do with how inheritance work (and I could assure you I know what I'm talking about, and I'm also pretty sure Timon knows also).
>
> Mistakes happen to the best of us. In this case the specification is correct
> and the bug report is in error. Derived classes may require less and provide
> more, which in contract lingo translates into weaker "in" contracts and
> stronger "out" contracts. This is not a matter in which reasonable people may
> disagree and not a matter of opinion.
I think you misunderstood what we are talking about here, as Walter is.
Nobody here discussed teh fact that in contract shouldn't become weaker when
inherited. This is, indeed, what corect OO design is.
What is discussed here is, with all details.
class A {
void foo() in { ... } body { ... }
}
class B : A {
override void foo() in { ... } body { ... }
}
then, let's consider :
fizbuzzA(A a) {
a.foo(); // A.foo's in contract is valid
}
fizzbuzzB(B b) {
b.foo(); // (A.foo OR B.foo)'s in contract is valid
}
The point is that B.foo's in contract loosen A.foo's in contract. And fizzbuzzA
have no knowledge of the fact that a subclass of A's instance can be passed.
So, if fizzbuzzA use foo with parameter that validate A.foo's in contract, but
not B.foo's in contract, it is an error. fizzbuzzA have no knowledge of the
runtime type of a, so shouldn't pass argument to foo that is invalid according
to A.foo's in contract. If it does, it means that fizzbuzzA is bugguy, or does
know about that fact that a isn't of type A, which is exactly what we DON'T
want when doing OOP.
It is Liskov substitution principle, any object of type B can be substituted to
an object of type A without the code using the object knowing about it. It is
probably the most important thing in OOP.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list