digitalmars.D - Overriding mixed-in virtual functions
- Max Samuha (28/28) Nov 16 2006 Is there a way to disambiguate the mixed-in virtual functions in a
 - Hasan Aljudy (16/50) Nov 16 2006 It would be nice if there was a "namespace" keyword.
 - Max Samuha (90/105) Nov 17 2006 Or reuse 'with' keyword for mixin instances rather than mix in
 
Is there a way to disambiguate the mixed-in virtual functions in a
derived class?
template TFoo
{
	void bar()
	{		
	}
}
class Base
{
	TFoo A;
	TFoo B;
}
class Code : Base
{
	override void bar(); // bad idea;	
}
Maybe I'm asking for too much, but it would be nice to be able to do
something like this:
class Code : Base
{
	override void A.bar()
	{
	}
	override void B.bar()
	{
	}
}
 Nov 16 2006
Max Samuha wrote:
 Is there a way to disambiguate the mixed-in virtual functions in a
 derived class?
 
 template TFoo
 {
 	void bar()
 	{		
 	}
 }
 
 class Base
 {
 	TFoo A;
 	TFoo B;
 }
 
 class Code : Base
 {
 	override void bar(); // bad idea;	
 }
 
 Maybe I'm asking for too much, but it would be nice to be able to do
 something like this:
 
 class Code : Base
 {
 	override void A.bar()
 	{
 	}
 
 	override void B.bar()
 	{
 	}
 }
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;
     }
 Nov 16 2006
On Thu, 16 Nov 2006 13:31:16 -0700, Hasan Aljudy
<hasan.aljudy 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.
    
  
 Nov 17 2006








 
 
 
 Max Samuha <maxter i.com.ua>