[racket] public, override -- how to combine

From: Roman Klochkov (kalimehtar at mail.ru)
Date: Sat May 24 05:46:28 EDT 2014

 I'm making something like ORM. ORM class has methods `read' and `write' (implements interface orm<%>). But ORM class may have as a super either ORM class or simple class. 

And here I have a problem, that simple class doesn't implement interface orm<%>, so I have to introduce new methods, 
but if superclass is ORM class, then I have to override.

Another example is a mixin. Suppose I have an interface printable<%> = (interface () print)) and I want to make a mixin printable, that should make any class to implement printable.
The only solution is:

(define (printable %)
   (if (method-in-interface? 'print (class->interface %))
       %
       ((mixin () (print) (define (print) (displayln this))) %)))


Sat, 24 May 2014 10:25:53 +0200 от Laurent <laurent.orseau at gmail.com>:
>Hi Roman, 
>
>Out of curiosity:
>I'm having difficulties finding a case where that would be necessary, unless when using an object there is a check to see if its class has the method or not, or if the class system does that itself and does nothing in case the method does not exist (instead of raising an exception).
>IMHO this would be better implemented with a void method in the parent class that can be overridden, or by implementing interfaces and check if the object is of one interface or the other. Override-or-declare doesn't strike me as good OO design (but if C++ does it, maybe there's a good reason).
>Could you give a simple use case?
>
>Laurent
>
>
>On Sat, May 24, 2014 at 8:16 AM, Roman Klochkov  < kalimehtar at mail.ru > wrote:
>>Is there a way to make C++ way inheritance: if superclass has the method, then override, else create new?
>>
>>I see in manual, that public requires " method must not be present already in the superclass" and override requires "definition already present in the superclass".
>>
>>Is it possible to not restrict the superclass?
>>
>>
>>-- 
>>Roman Klochkov
>>____________________
>>  Racket Users list:
>>   http://lists.racket-lang.org/users
>>
>


-- 
Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140524/0715de39/attachment-0001.html>

Posted on the users mailing list.