A question about substitution principle



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





.



Relevant Pages

  • Re: Best forum for OOD/Design by Contract discussions?
    ... relates to Design by Contract? ... DbC is a tool that was originally developed in R-T/E back in the '60s because it provides a rigorous approach to designing interactions among multiple state machines. ... The precondition includes algorithmic sequencing defined in requirements and the state of the overall solution as expressed in terms of state data values. ... Whatever that other behavior did can be expressed in terms of a postcondition on executing that other behavior. ...
    (comp.object)
  • Re: Client/Service relationships & Flow of Requirements.
    ... 'Observer' mean in the GoF pattern. ... Thus the precondition for executing the ... Observer action is not a precondition on a specific Subject object; ... The called must guarantee the postcondition is true *to the caller*, so it can't change the postcondition to suit its own purposes. ...
    (comp.object)
  • Re: Liskov Substitution Principle and Abstract Factories
    ... LSP tells that B's precondition should be the ... and postcondition should be the subset of A's. ... So if we want to substitute B for A (with seperate no contract enforcment), ...
    (comp.object)
  • Re: precondition and postcondition
    ... >precondition by a weaker one, and its postcondition by a stronger one. ... An overriding method may strengthen the postcondition. ... class Rectangle { ... virtual void setHeight{ ...
    (comp.object)
  • Re: before after methods and call-next-method
    ... then the postcondition will be true if the function returns. ... let's assume that all the elements of the precondition ... Now suppose we implement a primary method that implements the generic ... method specializing on C. ...
    (comp.lang.lisp)