A question about substitution principle
- From: "Tony Johansson" <johansson.andersson@xxxxxxxxx>
- Date: Sun, 25 Sep 2005 10:09:40 GMT
Hello!
I read in some paper about substitution principle and there is something
that I don't understand so I ask you.
The substitution principle and Bertand Mayes says that a routine may only
replace the original precondition by one equal or weaker and the original
postcondition by one equal or stronger.
Figure 1: operation top element from a stack using weak contract
Precondition: true
Postcondition: If not empy
then result = top element from stack
else throw EmptyException
Figure 2: operation top element from a stack using strong contract
Precondition: true
Postcondition: result = top element from stack
The substitution principle and Bartrand Mayer say that in particular it does
not make Figure 1 define a subtype of figure 2.
Cerainly, the precondition of Figure 1 is weaker than that of Figure 2. The
postcondition of Figure 1, however, is not stronger than that of Figure 2,
since a thrown exception satisfies the former but not the latter.
Now to my question: I don't understand what it means with "The postcondition
of Figure 1, however, is not stronger than that of Figure 2, since a thrown
exception satisfies the former but not the latter."?
How should the postcondition of Figure 1 and Figure 2 should look like if
Figure 1 would satisfies
to be called a subtype of Figure 2.?
I have believed about this postcondition if Figure 1 include Figure 2
postcondition and in addition
add some more postcondition for example as in this examle throw some
exception then it Figure 1
satisfies the definition of being called a subtype of Figure 2.
//Tony
.
- Follow-Ups:
- Re: A question about substitution principle
- From: Dmitry A. Kazakov
- Re: A question about substitution principle
- Prev by Date: Re: Use Case Point Estimation
- Next by Date: Interface complexity problem in game
- Previous by thread: Looking for some advice on No Magic's Teamwork version control server
- Next by thread: Re: A question about substitution principle
- Index(es):
Relevant Pages
|