dynamic classes and duck typing
Ary Borenszweig
ary at esperanto.org.ar
Tue Dec 1 04:01:20 PST 2009
retard wrote:
> Tue, 01 Dec 2009 03:16:47 -0800, Walter Bright wrote:
>
>> Ary Borenszweig wrote:
>>> Can you show examples of points 2, 3 and 4?
>> Have opDispatch look up the string in an associative array that returns
>> an associated delegate, then call the delegate.
>>
>> The dynamic part will be loading up the associative array at run time.
>
> This is not exactly what everyone of us expected. I'd like to have
> something like
>
> void foo(Object o) {
> o.duckMethod();
> }
>
> foo(new Object() { void duckMethod() {} });
>
> The feature isn't very dynamic since the dispatch rules are defined
> statically. The only thing you can do is rewire the associative array
> when forwarding statically precalculated dispatching.
Exactly! That's the kind of example I was looking for, thanks. Also:
class Foo {
... opDispatch ...
}
class Bar : Foo {
// Let's make Bar understand more things...
... opDispatch ...
}
Foo foo = new Bar();
foo.something();
will not work as expected because something() will be bound to Foo's
opDispatch and it isn't a virtual method. Of course you can make
opDispatch invoke a virtual function and override that function in Bar,
but since there isn't a standard name or method for doing this everyone
will start doing it their way (I don't like it when there's no
standarization for well-known operations) and it looks like a hack.
More information about the Digitalmars-d
mailing list