From: Jamis Buck Date: 2004-11-12T03:28:48+09:00 Subject: Re: Thinking About Java Interfaces In Ruby Francis Hwang wrote: > > On Nov 11, 2004, at 1:07 PM, Jamis Buck wrote: > >> The *only* time I've thought interfaces would be nice is when I >> considered finding a way to implement type 1 inversion of control. >> This is where a service just says "I need another service that >> implements this interface" and the container goes and finds one that >> matches. >> >> Even then, I was only thinking it would be neat to implement for the >> "gee-whiz" value, not because I actually needed that feature. > > > If you want to be really far out, you can write code that infers this, > by looking to see if various methods are defined. I've done this in > extremely simple cases, and I wonder if there's a use for the idea in > broader contexts, but that sort of feels like PhD stuff. True, and I considered that (the approach, not the PhD :-P). However, most of the time, the interface that is desired is only a small subset of the methods published by the object... Also, things are further complicated by the fact that you can't just look at a service definition and determine its interface by reflection. This is because the service definition (in Needle) is what is returned by executing a block, and I'd like to be able to get the interface information without having to execute the block (and thereby actually instatiate the object). I've considered having service declarations explicitly name the methods they export, but that's where things just become too much work. Besides, "interface injection" just doesn't feel very Rubyish, especially since interfaces in Ruby can be changed on the fly, and may even differ from one object to the next, even though they share the same instantiating class. - Jamis -- Jamis Buck jgb3@email.byu.edu http://www.jamisbuck.org/jamis