Feng Yu <rainwood...@...> writes:

> 
> 
> On Thu, May 21, 2009 at 3:25 PM, Vlad Grecescu <b100dian <at> gmail.com> 
> wrote:
> 
> 
> 
> On Tue, May 19, 2009 at 1:47 AM, Andrea Del Signore
<[email protected]> wrote:
> 
> On Mon, 2009-05-18 at 15:12 -0400, Feng Yu wrote:
> > public interface Iface {
> >   public void function() {
> >     message("do somethign");
> >   }
> > }
> >
> > public class Class:Object, Iface {
> >   public void function() {
> >    message("class do something");
> >    base.function();
> >  }
> > }
> Hi Yu,
> the base keyword will chain the function call to the parent
> class (which in this case is a GLib.Object) and not to any implemented
> interface.
> If you want to call the Iface.function member just use a cast like:
> 
> public void function() {
>         message("class do something");
>         ((Iface) this).function ();
> }
> Regards,
>         Andrea
> 
> 
> 
> 
> Interesting - I suppose this works because the function is not virtual? 
> 
> Right. In Vlad's Iface no virtual function is defined.This is the compiled
ccode:struct _TestIfaceIface {┊   GTypeInterface parent_iface;};On the other
hand, simply do this:namespace Test{       public interface Iface {        
public virtual /*VIRTUAL!*/ void function() {
>            message("do something");         }       }       public class
Class:Object, Iface {         public void function() {          message("class
do something");          ((Iface) this).function(); // or           ((Iface)
base).function();
>         }       }       public static void main(string[] args)      
{               var t = new Class();               t.function ();       }}to get
into the infinite loop. It make sense for (Iface) this).function() to invoke the
infinite loop, because in 'Class' Iface.function is overriden by Class.function.
However there should be a way to access the interface's default implementations.
Or else it would be very sad.
> There is no such a thing in Java, because in Java interfaces are not allowed
to have implementations.What about C#? I think a cast on the base access within
an implemented virtual function's scope should be a suitable candidate for this
particular chaining up.Yu

Hi,

like Java also C# doesn't allow implementations in interfaces, so this is a
special Vala / GObject case. From the C# side there's another interesting
detail: modifiers like private / public or virtual aren't allowed in interface
methods too.

Anyway I agree with Yu a ((Iface) base) cast could be used in this case.

Have a nice day,
   Andrea


_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to