[D.typesystem] Suggestion for improving OO inheritance models

Andrej Mitrovic andrej.mitrovich at gmail.com
Wed Sep 1 14:41:42 PDT 2010


Ah nevermind. I didn't realize you've said "overload".

On Wed, Sep 1, 2010 at 11:39 PM, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> You mean like this?:
> module add_virtual_functions;
>
> import std.stdio : writeln;
>
> void main()
> {
>    test();
> }
>
> mixin template Foo()
> {
>    void func()
>    {
>        writeln("Foo.func()");
>    }
> }
>
> class Bar
> {
>    void func()
>    {
>        writeln("Bar.func()");
>    }
> }
>
> class Code : Bar
> {
>    mixin Foo;
> }
>
> void test()
> {
>    Bar b = new Bar();
>    b.func();   // calls Bar.func()
>
>    Code c = new Code();
>    c.func();   // calls Code.func()
> }
>
>
> On Wed, Sep 1, 2010 at 11:30 PM, Jacob Carlborg <doob at me.com> wrote:
>> On 2010-09-01 22:44, Philippe Sigaud wrote:
>>>
>>> On Wed, Sep 1, 2010 at 18:13, retard <re at tard.com.invalid> wrote:
>>>
>>>
>>>    Have you taken a loot at Scala & traits already? It would be a great
>>>    starting point.
>>>
>>>
>>> Scala's traits are great! Implicits in Scala are quite interesting too.
>>> Also, Haskell typeclasses
>>>
>>> I wonder if D can have part of Scala traits functionality with mixins?
>>
>> You can't use D template mixins to add methods that will overload existing
>> methods.
>>
>>
>> --
>> /Jacob Carlborg
>>
>


More information about the Digitalmars-d mailing list