From: Nat Pryce Date: 2002-03-13T02:15:26+09:00 Subject: Re: Method type 'abstract' In a statically typed language, such as Java, the compiler would catch that you had not implemented an abstract method. In a dynamically typed language like Ruby, one uses unit tests for this: * Write tests that define the required behaviour of all classes derived from your abstract class. * Run those tests over an instance of each concrete class. In practice, you have to use unit tests for this in statically typed languages as well, because although a concrete class may implement an abstract method, it may not implement it correctly. There are many potential errors that cannot be caught by the type system. Cheers, Nat. ________________________________ Dr. Nathaniel Pryce B13media Ltd. 40-41 Whiskin St, London, EC1R 0BP, UK http://www.b13media.com ----- Original Message ----- From: "Peter Hickman" To: "ruby-talk ML" Sent: Tuesday, March 12, 2002 4:57 PM Subject: Re: Method type 'abstract' > Nat Pryce wrote: > > >In Ruby *all* methods are abstract unless implemented by a class. > > > >Or to put it in a more useful way, abstract methods are not required in a > >dynamically typed language such as Ruby, only in typed languages like Java > >or C++. > > > Not quite what I had in mind. If I create a class I will provide various > methods that a subclass can override. But in many cases they will pick > up the super classes' methods. However in the class I have in mind there > is one method that must exist in the subclass for which there is no > meaningfull default action that it can undertake, the subclass must > override this method. In Java I would mark the method as abstract rather > than just public or private and when I subclass it the compiler would > choke if I did not provide the override in the subclass. > > At present I have to insert a normal method in the class that raises an > exception which will then cause the subclass to fall over if it did not > override it. It works but it isn't clean, to my mind abstract is just as > fundemental as public or private and therefore should be marked as such. > > I have a deep suspicion that the way Ruby does things means that this is > not possible, just thought I would ask though. >