On Tue, Oct 01, 2002 at 02:49:49PM -0700, Michael Lazzaro wrote: > >>My musing is that the behavior of a class in different contexts is > >>itself an interface, in the sense of being a contract between a > >>class/subclass and it's users > > > >Ah HA! Contract! Return values can be enforce via a simple DBC post > >condition, no need to invent a whole new return value signature. > > I think I get it, but can you give some pseudocode? If you want a > method to return a list of Zoo animals in "list" context, and a Zoo > object in "Zoo object" context, what would that look like?
The trick is having some way of getting at the return value. Class::Contract does this by having a magic value() function you can call in a post-condition. I can't think of anything better, so... class Animals; method zoo { ... # I have no idea what actual post condition syntax will look like post { given want { when 'LIST' { grep { $^thing.isa('Zoo::Animal') } value() } default { value().isa('Zoo') } } } } It might be nice if the return value was the topic of the post condition, but that leads to problems of how you deal with lists as topics which I don't know if they've been solved. > (I'm assuming that DBC postconditions on a method would be treated, > internally, as part of the overall signature/prototype of the method: > i.e. if you override the method in a subclass, all original > postconditions would still remain attached to it (though the new method > might itself add additional postconditions.)) That's how I understand it works. -- Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/ Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One I'm a man, but I can change... if I have to. -- Red Green