Re: [Vala] Interfaces and Mixins



On Tue, 2010-06-15 at 14:50 -0700, Robert Powell wrote:
On Sat, Jun 12, 2010 at 7:03 AM, tecywiz121 <tecywiz121 hotmail com>
wrote:
        Hey,

Hey!
 

        
        The following code won't compile unless I create a flush() in
        Concrete,
        but I can't seem to access Entity.flush() at all, any way
        around this
        that doesn't involve making Entity a class?
        public interface Flushable : Object
        {
           public abstract void flush();
        }
        
        public interface Entity : Object, Flushable
        {
           public virtual void flush()
           {
               // Do Something
           }
        }
        


What are you trying to accomplish by having both Flushable and Entity?
I think you are trying to create different mixin implementations of
Flushable, which seems like a perfectly reasonable thing to do.

I am trying to have a type hierarchy like so

Flushable
    | \
    |  \
 Entity \
    |    \
    |     FlushableNonEntity
 SomeObj

Where SomeObj's implementation of Flush comes from entity, but
FlushableNonEntity's does not.

You can access Entity.flush by casting this to an Entity.  I think
you'll find that when you refer to the object you will receive GObject
warnings about cannot add interface type 'Entity'.  Even without the
name collision of flush, this GObject warning will still occur.

Wouldn't the following code (not sure, haven't tried) just recurse
infinitely?

public object Bob : Object, Flushable, Entity
{
    public void flush()
    {
        ((Entity)this).flush();
    }
}

Deriving interfaces from interfaces is definitely broken.  You might
want to submit a bug.

Actually in my other interfaces, it works fine.  I'm just not sure if
I'm allowed to override a method declared in Flushable in Entity.

Hope that helps,

Rob

It kinda does, thanks

Sam





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