[Vala] interfaces in vala



I was unable to find a way to use interfaces in vala, are they supported yet?

I have finally managed to do the same with abstract classes with virtual methods
and normal classes overriding these virtual methods.

Here's the source:

---------------------------
using GLib;

public abstract class Boing : Object
{
        public virtual void run() {}
}

public class Aboon : Boing
{
        public override void run()
        {
                stdout.printf("This is new!\n");
        }

        public static void main()
        {
                Boing foo = new Aboon();
                foo.run();
        }
}
---------------------------

This is how interfaces should work (if they don't do this already), but text
translation is quite simple, no idea how hard would be to implement:

public interface Boing
{
        public void run();
}

public class Aboon : Boing
{
        public void run()
        {
        }

        public static void main()
        {
        }
}

The differences are quite obvious:

 - Support for defining method descriptors without body
 - All methods of an interface are marked as virtual
 - The interface is handled as an 'abstract class'
 - All methods defined in the interface are marked as 'override' in the implementor one.

I will use the abstract/virtual/override way, but I will find more readable the
'interface' solution which looks the same as in csharp or Java.


--pancake



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