Re: Design by Contract
| From: | Dmitry Stogov | Date: | Tue, 10 Feb 2015 08:19:43 +0000 |
| Subject: | Re: Design by Contract | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-82350@lists.php.net to get a copy of this message | ||
completely agree. contracts must be permanent.
Thanks. Dmitry.
On Tue, Feb 10, 2015 at 10:40 AM, Joe Watkins <pthreads@pthreads.org> wrote:
> Example code never works, I can just say that's a bad abstraction,
> vertebrate and invertebrate are distinct and abstraction should reflect
> that.
>
> Why should we provide a way to change contracts is the question ?
>
> It doesn't seem to make sense to do that, a derived class should be able
> to define additional contracts, but not change the contracts of it's parent.
>
> Cheers
> Joe
>
> On Tue, Feb 10, 2015 at 7:36 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
>
>> 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
>>
>
>