[fxruby-users] Inheritance

Meinrad Recheis meinrad.recheis at gmail.com
Thu Feb 9 15:34:02 EST 2006

On 2/9/06, Uwe Hartl <uwe.hartl at gmx.net> wrote:
> Hi,
> I want to create an object from data I have no idea which type it is. Assuming
> I have the possibilities to have an date and an int. Now I want to create
> from both an object that has the the same capabilities (e.g. show itself in a
> parent FXFrame). But there should be specific things for the different data
> types to be modified (the textfield for the int should just allow numbers and
> the textfield of the date should allow numbers and ":" and there should be a
> button beside it which pops up a FXCalendar Dialog). what I want is basically
> to create a class (lets call it Data), which has a constructor which figures
> out from which class (DateVis or IntVis) itself should inherit. Something
> like this:
> class Data
>         def initialize(d)
>                 if d.class == "Fixnum"
>                         inherit from IntVis
>                 elsif d.class == "Date"
>                         inherit from DateVis
>                 end
>         end
> end
> I don't get it done. Does anybody have a clue if this is possible? Kind of
> inheritance after the fact of creation?

use the MVC pattern! don't mix data and view classes (allthough fox did it)
when you want to display your data instantiate the apropriate view to
display it.
you may have a FixnumView class and a DateView class which listen to
changes in the data and display it.

just my 2 cents,
-- henon

More information about the fxruby-users mailing list