Re: [Vala] Extension Methods



Feng Yu wrote:
What about this:

public extend class Gtk.Widget {
    public bool set_gl_capability (GdkGl.Config glconfig,
Gdk.GlContext? share_list, bool direct, int render_type) {

      // do stuff.
    }
}

AKA, when vala encounters the extend keyword, instead of panicing
duplicated class declarations, it simply add the decleration to the
existing class.

'extend' could be confused with subclassing (for example Java uses the
'extends' keyword for subclassing).

I know this feature from Objective C, where it's called "categories":
http://en.wikipedia.org/wiki/Objective_c#Categories

These 'categories' are even named, so you can group these additional
methods thematically. If Vala considers such a feature I would propose
the following syntax:

 public class string category SpellChecking {
     // ...
 }

 public class Gtk.Widget category GLFunctionality {
     public bool set_gl_capability (...) {
         // do stuff.
     }
     // ...
 }

These category names would get lost in C code, but they could be nice
additional information in a Vala object browser.


Regards,

Frederik



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