Inheritance hierachy: Class from Abstract class from Interfaces, does not enforce method implementation?

zack no-way-zack at no-web.de
Wed Mar 24 08:22:51 UTC 2021


Sorry for the weird title.
I dealt with interfaces and abstract classes and came accross a 
behavior I didn't expect. Can someone clarify if this behavior is 
wanted?

I have multiple interfaces, were an abstract class inherits from. 
The abstract class however, just defines part of the functions to 
be abstract and does not implement the others. A concrete class 
then finally derives from the abstract class.

So I as a user would expect that the concrete class implements 
all methods defined in the interfaces. However, this seems to not 
be the case. The following code compiles just fine, even if baz() 
was never implemented. Calling the baz() function on a Concrete 
object causes the program to crash.

interface A {
	void foo();
}

interface B {
	void baz();
}

class Abstract : A, B {
	abstract void foo();
}

class Concrete : Abstract {
	override void foo()	{ writeln("foo"); }
}


More information about the Digitalmars-d mailing list