Overriding mixed-in virtual functions
Max Samuha
maxter at i.com.ua
Fri Nov 17 03:23:20 PST 2006
On Thu, 16 Nov 2006 13:31:16 -0700, Hasan Aljudy
<hasan.aljudy at gmail.com> wrote:
>
>It would be nice if there was a "namespace" keyword.
>
>class Code : Base
>{
> namespace A
> {
> override void bar() {...} //Yatta!
> }
>}
>
>and, a mixin name
>
> mixin TFoo A;
>
>can be just a short cut for:
>
> namespace A
> {
> mixin TFoo;
> }
Or reuse 'with' keyword for mixin instances rather than mix in
templates into a namespace? A new keyword is not likely to creep into
the language before 1.0. And 'with' is already used in a similar way
for template instances
template TFoo()
{
void bar()
{
}
}
void main()
{
alias TFoo!() Foo;
Foo.bar();
// or
with(Foo)
{
bar();
}
}
And for mixins it could be
class Base
{
mixin TFoo A;
mixin TFoo B;
}
class Code : Base
{
override void A.bar()
{
}
// or
with(A)
{
override void bar();
}
}
BTW, i (and hopefully other people programming in D) would really like
the following to be defined in the specs before 1.0:
1. Which mixin implements the interface method?
interface IFoo
{
void foo();
}
template TBar
{
void foo()
{
writefln("In foo");
}
}
class Code : IFoo
{
mixin TBar A;
mixin TBar B;
// Is IFoo.foo implemented by A.foo or B.foo?
}
2. The order of mixed-in overrides is important.
This compiles:
class Base
{
void bar()
{
}
}
class Code : Base
{
void bar() // Fast enough to override the base bar
{
writefln("Base bar");
}
mixin TFoo A;
mixin TFoo B; // A.bar and B.bar live happily together
}
This doesn't:
class Code : Base
{
mixin TFoo A;
mixin TFoo B; // No way: A.bar has already overriden the base
bar
void bar()
{
writefln("Base bar");
}
}
There mignt be more related issues I can't think of.
More information about the Digitalmars-d
mailing list