Hi!
From: Göran Krampe goran@krampe.se
- Interfaces. Yes, might be neat to have. Traits touch on this a bit and
we also have SmallInterfaces (which I never have looked at). I really don't know if it would hurt more than it would help.
Touches on a bit? Java interfaces are nothing more then c++ base classes that have virtual methods that deriving classes must implement. Traits is already better then this by at least allowing you to specify what the default code implementation is.
AFAIK Traits is not intended as "specification of protocol" that you can check against (during runtime or in some interesting way - compile time). Sure, they *are* comprised of a bunch of methods - and sure - we could probably (mis)use them as interfaces/protocol-specifications - but... I couldn't really say at this point because alas, I haven't used them yet. :)
Ok, let me take the opportunity to flesh out a trivial idea:
As most people know a java interface is a "named bunch of messages" that a class (or its superclasses of course) can declare it implements. But this is early binding, right?
I would be more interested in "late" binding where I could do:
someThingy respondsToProtocol: aProtocol
...where aProtocol is more or less just a bunch of selectors. The main difference is of course that the class (or any of its superclasses) of someThingy doesn't need to *declare* that it implements aProtocol - it just has to actually do it. :)
This means in practice that the code using someThingy (written later by developer X) can declare what messages it actually intends to send to someThingy instead of the other way around. IMHO this decouples the writing of someThingy from the code using it *in time*.
Now... one place where this might be useful is in unit tests. Or hey, I dunno, just felt like a Smalltalkish way of using "interfaces". :)
regards, Göran
PS. Btw, anyone recall the syntactic changes that was introduced in one of the older VWs? Perhaps around version 2.5 or so. The Compiler could actually parse "parameter type checks using some <...>-syntax IIRC" but when I looked closer in the code it didn't actually do anything with it yet. Eh... have no idea why this popped up in my head right now. ;)