Re: [Vala] implementing interface properties through inheritance



I'm also wondering why it's necessary to define the property in Child, given that it already exists in Base (the C code won't compile otherwise). I'm thinking property inheritance should be consistent with method inheritance (it isn't necessary to explicitly override an abstract method when a compatible method exists in Base).

Also note that a get/construct (not set) interface property does not support setting its values in the constructor in an implementing class (the C code fails to compile). This is probably a bug.

On Sun, Aug 31, 2008 at 9:03 AM, Michael Lawrence <mflawren fhcrc org> wrote:
When an interface declares a property, and a class implementing that interface inherits from a class that implements a property of the same name, what should happen?

Here is some Vala code that explicitly implements the interface property by calling up to the base class. With [NoAccessorMethod], Vala needs to use g_object_get() to get the property by name. But what property will it get? Unfortunately, it just seg faults. If I omit [NoAccessorMethod], Vala gets the field directly, and everything works as expected (the base property is retrieved).  So if Base is defined in an external library (brought in via vapi), and there's no accessor methods (and even if there were, they might use g_object_get/set), what should be done in this case?

public interface Interface {
  public abstract bool prop { get; set construct; }
}

public class Base : Object {
  [NoAccessorMethod]
  public bool prop { get; set construct; default = true; }
}

public class Child : Base, Interface {
  public bool prop {
    get { return base.prop; }
    set construct { base.prop = value; }
  }
  public static void main(string[] args) {
    Child child = new Child();
    if (child.prop)
      debug("from base");
  }
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]