<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, May 24, 2014 at 11:46 AM, Roman Klochkov <span dir="ltr"><<a href="mailto:kalimehtar@mail.ru" target="_blank">kalimehtar@mail.ru</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>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. <br><br>And here I have a problem, that simple class doesn't implement interface orm<%>, so I have to introduce new methods, <br>
but if superclass is ORM class, then I have to override.<br></div></blockquote><div><br></div><div>Then here you should use `implementation?` instead of `method-in-interface?`, and in case the class does not yet implement `orm<%>`, make it implement it, instead of just adding the method.<br>
</div> <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>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.<br>
The only solution is:<br><br>(define (printable %)<br> (if (method-in-interface? 'print (class->interface %))<br> %<br> ((mixin () (print) (define (print) (displayln this))) %)))<br></div></blockquote>
<div><br></div><div>Here too, and the new class should implement `printable<%>` instead of just implementing the method.<br></div><div>Then to know if you can call `print` on a given object, you should first check that it implements `printable`.<br>
<br></div>Checking for the implementation of the right interface ensures that the method does what you think it should do; because maybe someone has defined another interface `my-printable<%>` that also declares `print` but has a quite different purpose from `printable<%>`.<br>
<div></div><div><br></div><div>Maybe I'm totally missing something here, but the only correct use I see to `method-in-interface?` is in Racket's implementation of the class system, to check for errors if the method is called but may not exist.</div>
</div><br></div><div class="gmail_extra">Laurent<br></div></div>