From: Geoff Youngs Date: 2003-11-21T23:21:35+09:00 Subject: Re: New Type Checking System Idea On Fri, Nov 21, 2003 at 11:17:16AM +0900, Greg McIntyre wrote: > Geoff Youngs wrote: > > I've played with a soft interface implementation which works > > reasonably well where I've used it... > Oooh, how does it work? > I tried redefining Module#append_features to call a hook which can be > defined to check for the methods the module needs. The only drawback > is you have to include your modules down the bottom of the class. It > doesn't work for inheritance however because Class::inherited is > called at the start of a class definition, not at the end. It's not perfect, but with a decent interface definition you're less likely to be using inheritance that way and you will also have inherited the required methods from the parent class anyway, unless you go on to re-define them which can't be easily prevented anyway, even in the same class. > So far that's the best Ruby 1 patch-up job I can do to get, as you put > it, soft interface checking. That is, the best without introducing a > lot more ugly code... That's pretty much what it does. It's possible that something else could be acheived with redefinitions of initialize or new or something so that a class can't be instantiated until the interface requirements are complete, but that might be a bit like overkill... It's not perfect, but this approach has met my needs for interfaces so far, TTFN, Geoff.