[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] Subclassing GTK "Classes" possible?
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] Subclassing GTK "Classes" possible? |
Date: |
Mon, 25 May 2009 08:12:52 +0200 |
User-agent: |
Thunderbird 2.0.0.21 (Macintosh/20090302) |
Joachim Jaeckel wrote:
> Hello,
>
> I'm currently trying something like
> "GTK.GtkWindow subclass: MainWindow"
>
> But maybe, that is not possible, because GtkWindow is no real class, but
> a binding?
More or less -- because GtkWindow>>#new: is not a real method, but a
binding. Binding classes are not special; binding methods are.
It would not be hard to add a feature to the VM and use it in GtkWindow
class>>#new:, so that an instance of your MainWindow class would be
returned. There is a disadvantage: that in many cases you would not be
able to override methods---because the overrides would have to be linked
to the vtable of a GTK class.
So, I am not sure whether the advantage balances the disadvantage.
Gwanael's code is using containment instead, with a separate class
hierarchy rooted at a simple class that is just a container of
GtkWindows. I think I prefer that approach.
> I know I have a lot to learn, currently I'm a bit confused about the
> fact, that "new" is a class-method and with the things that have an
> association with that.
>
> In Java I would call in the constructor of a subclassed class e.g.
> super(bla); to initialize the object. How could that be done in smalltalk?
You can do that with "^super new initialize" or better "^self basicNew
initialize" (#basicNew is defined to be the same as Object's
implementation of #new). The latter is better because it avoids double
initialization in case "super new" was already calling #initialize.
Thanks!
Paolo