From: Dave Thomas Date: 2002-02-05T04:25:05+09:00 Subject: Re: Subclassing vs Subtyping (partly OOP vs FP) Robert Feldt writes: > I guess there is no easy way out of the problem that you can't > semantically check methods unless you describe the semantics in a > machine-understandable form. The good thing with describing the semantics > is that we get an oracle that can be used for testing. I think I was thinking about something less ambitious/. Say you have out friend BagCollectable that implements bag functionality for some container. BadCollectable relies on its host class implementing methods #add, #remove, #includes? and #each, and exports a bunch of cosmetic methods based on these. We have a set of implementations: class BTreeBag include BagCollectable ... end class ArrayBag include BagCollectable ... end class LinkedListBag include BagCollectable ... end etc Then we _could_ arrange it so that BagCollectable did some basic checking if (say) the -d flag was set: 1. It could check that classes it was mixed in to defined the methods it needed. 2. It could generate some basic tests, exercising each class in to which it is mixed by calling their #add, #remove, etc methods Then take it a step further, and break these tests out into a separate module: class BTreeBag implements BagProtocol includes BagCollectable ... end Regards Dave