Re: Inheritance (Was:Non-technical Glib advise needed)

On Sun, 2004-01-11 at 15:09, John (J5) Palmieri wrote:
GObjects supports inheritence so it might be a good solution to your
dependecy graph.

But only inheritance of the creation and destruction methods, right ?
There's no way to do polymorphism though, right ?  To illustrate:

Suppose I have

    ^    ^
    |    |
GCircle  GSquare

and I have

g_drawing_object_draw (GDrawingObject *, GdkGC *, GdkDrawable *) ;
g_circle_draw (GCircle *, GdkGC *, GdkDrawable *) ;
g_square_draw (GSquare *, GdkGC *, GdkDrawable *) ;

as well as a piece of code that says

GCircle *circle ;
GSquare *square ;

circle = g_circle_new (120, 100, 50) ;
square = g_square_new (0, 10, 32, 32) ;
g_drawing_object_draw (G_DRAWING_OBJECT (circle), gc, window) ;
g_drawing_object_draw (G_DRAWING_OBJECT (square), gc, window) ;

Now, I want g_drawing_object_draw to somehow end up calling
g_circle_draw for circle and g_square_draw for square.  How can I do
that ?  I suppose if I did some runtime type checking using the typing
system on square and circle, I could make the right decision.  However,
what if GCircle and GSquare themselves have subtypes ?  I would have to
modify g_drawing_object_draw everytime I add another subtype.

Moral of the story:  Can anybody show me a systematic way of doing
polymorphism using GObject ?

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