Re: Design by Contract
| From: | Yasuo Ohgaki | Date: | Tue, 10 Feb 2015 07:36:24 +0000 |
| Subject: | Re: Design by Contract | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-82346@lists.php.net to get a copy of this message | ||
Hi Joe,
On Tue, Feb 10, 2015 at 4:31 PM, Joe Watkins <pthreads@pthreads.org> wrote:
> Actually I'm not sure it's at all sane to try to override contracts, I'd
> actually avoid that completely, so no need to name contracts and no need
> for magic __invariant.
For example,
class Animal {
protected $legs;
require($legs >= 0);
}
class Snake extends Animal {
// Snake is fine, no leg
}
class Human extends Animal {
// 2 legs. $this->leg === 2
}
Overriding makes sense for many cases.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net