djberg96
4/4/2005 3:23:00 PM
Richard Cole wrote:
<snip>
> My major gripe with Ruby is that there's no static typing.
Ruby is a dynamic language. You're still thinking in Java.
> I'd really
> like to be able to do something like:
>
> interface ISubject
> def notifyAll -- unit
> def addObserver(a -- IObserver) -- unit
> end
>
> interface IObserver
> def subjectUpdate(subject -- ISubject)
> end
> end
>
> class Subject
> def initialize
> @observerList -- ISubject IEnum = Array.new()
> end
> ...
> end
>
> Why? because interfaces gives you a place define and explain
protocols
> of interaction.
There's nothing you can do with an interface that I can't do better
with a mixin. You can also get the equivalent effect with
documentation and a test suite, e.g. "your package must implement
methods X, Y, and Z and pass the provided test suite". I believe Rails
uses the latter approach for verifying DB adapters, for example.
<snip>
> The major problem with interfaces is that you can't say later, oh,
this
> class implements that interface, but in Ruby, if there were
interfaces,
> the you could.
No, instead you use mixins and say, "this class mixes in that module".
And, instead of just stubs, you get an actual *implementation*.
All that being said, I wrote (with much help) an "interface" package,
mostly as a proof of concept. You can find it on the RAA.
Regards,
Dan