On 25 January 2011 23:36, Abderrahim Kitouni <[email protected]> wrote:
> Hi,
> في ث، 25-01-2011 عند 21:35 +1030 ، كتب James Moschou:
>> Is is possible to mark methods as virtual in interfaces, as a
>> mechanism of providing default implementations?
>>
>> If I do
>>
>> interface Interface {
>> public virtual void function () {
>> // Default
>> }
>> }
>>
>> class Class : Object, Interface {
>> public override void function () {
>> // Custom
>> }
>> }
>>
>> The compiler says that no method to override was found.
>
> but if you remove the override keyword, it works ;-)
>
> So now the question is : is this intentional? I always thought that you
> don't need override when implementing an abstract method (and need
> override when there is already an implementation), but it seems I was
> wrong. This probably needs an answer from Jürg (and the rationale to be
> added somewhere in the documentation).
>
> HTH,
> Abderrahim
>
>
I'm aware that it works if you don't use the override keyword, and it
does seem unintentional, considering that the behaviour of
abstract/virtual/override/new is pretty well defined for normal class
inheritance, and vala emits warnings if you don't do it correctly.
This issue is actually a precursor to my real question, which I don't
think has come up before on this list exactly, although similar
threads have touched on it.
I really want to be able to define a class as implementing an
interface with default implementations of virtual methods, and have
subclasses of that class override the virtual methods. So:
interface Interface {
public virtual void function () {
// Default
}
}
class Class : Object, Interface {
}
class Subclass : Class {
public override function () {
// Subclass implementation
}
}
But I suspect this is impossible with the way GObject is designed,
which would be a shame.
Regards,
James
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list