On 02/08/13 12:24, Phillip Lord wrote:
> "Jim - FooBar();" <
jimpi...@gmail.com> writes:
>> your extension point on Number is never fired because 10 is a Long.
> Sure, I understand why it's not working! I just don't know how to fix it.
there is nothing to fix in this particular example...everything works
as expected.
>
>> Generally speaking extending protocols to interfaces is not
>> suggested...
> I'm extending an API which is interface driven -- the OWL API in this
> case.
all well-designed APIs are abstraction driven. I imagine there nothing
special about OWL in that respect...
take for instance the openNLP API...It has 4 or 5 interfaces that define
the different components that openNLP supports (Tokenizer, Stemmer,
NameFinder etc etc).
I can easily extend-type to all these interfaces (that are all on the
same 'level') which allows me to cover all concrete classes. This is one
of the cases where it works for me just fine...
However if I try to extend a protocol to java.util.Collection and then
to clojure.lang.IPersistenVector it won't work...only the extension to
java.util.Collection fires (because it is above
clojure.lang.IPersistenVector). That is what I meant...
>
>
http://owlapi.sourceforge.net/javadoc/index.html
>
> At the moment I am just playing, but the idea was to extend this API so
> that it supports core.match.
>
>> I've been bitten a couple of times in particular whenever
>> I'm extending to 2 different interfaces that *are* related...You can
>> certainly do it but you have to have sure that your top interface
>> comes first than the others.
> In this case, that wouldn't work; I really need to call a superclass
> implementation.
>
> For instance, the class OWLEntity has one method on it that I need to
> call. It has 8 direct subintefaces, and quite a lot more below that. I
> don't want to have to support the single method multiple times.
I can see from the docs that OWLEntity is an interface and as you say it
has several subinterfaces. My approach would be to either extend only to
OWLEntity or all of the subinterfaces. If you try to do both, I suspect
only the top one will always be fired...If the implementation of the
method you want is identical for all, you can just bother with
OWLEntity or programmatically emit identical extension points for all
subinterfaces.
>
> I can think of otherways to do this, I guess, but they kind of involve
> lots of instance? checks.
apart from sounding like non-idiomatic code, it also sounds like
problematic code since you're dealing with interfaces that are related...
user=> (instance? Number 1)
true
user=> (instance? Long 1)
true
user=> (instance? Object 1)
true
>
> Phil
>
Jim