Peter Haworth wrote:

> That *is* a logical weakening. Just because the inherited precondition is
> C<< x > 10 >>, doesn't mean that the weakened condition has to be of the form
> C<< x > 9 >> or any other value lower than 10. C<< a || b >> is weaker than
> C<< a >>

So what we are looking at is something like....


class Animal {
   method eat($food) is abstract {
     PRE { $food.isa(Edible); }
     POST { !$stomach.empty; }
   }
...
}

class Goat is Animal {
   method eat($food) {
     PRE { $food.isa(Can); }
     my $chewedfood = $teeth.chew($food);
     $stomach.add($chewefood);
     $teeth.brush()
     POST { $teeth.clean; }
   }
...
}

class Teeth {
  method brush {...};
  method chew {
    ...
    POST { .clean == false; }
   }
}
my Animal $billy = new Goat;

$billy.eat(Banana.new());   # succeeds because PRE for Animal.eat is met
$billy.eat(Can.new());      # succeeds because PRE for Goat.eat is met
$billy.eat(Rock.new());     # Fails because neither PRE is met

class DirtyTeeth is Teeth {
   method brush {};
...
}

$billy.teeth = DirtyTeeth.new();
$billy.eat(Banana.new());   # Fails because POST for Goat.eat is not met

etc.

> 
>> Are there
>>other ways to do it, just to mull them over?
> 
> 





Reply via email to