Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-03-04 02:17:53


David Turner wrote:

> Hi
>
>> So, the code to implement graph drawing would have to be
>> freestanding function that takes window as parameter. What
>> does it buy?
>>
>
> Good design, for one thing. What business does a window have knowing
> about graphs? A window is a window is a window. Same for a drawing
> surface. I've seen too many 3000-line CMyDialog: public CDialog classes
> to buy the reuse-is-inheritance argument.

So, if I want to create a widget for drawing graph, I'll have to write:

   void draw_the_graph(window w, ....)
   {
          .....
   }

   void handle_click(window w, ....)
   {
        // Add new vertex
   }

   void handle_right_click(window w, ...)
   {
        // show vertex properties, if mouse points
        // to a vertex
   }
     
   window make_graph_widget()
   {
         windows w;
         w.on_draw = &draw_the_graph;
         w.on_mouse_click = &handle_click;
         w.on_mouse_right_click = &handle_right_click;
         return w;
   }

? What are the chances that handle_right_click can be reused anywhere else,
is it really independent from GUI, and isn't this too complex a solution?

Note that I buy the idea of non using inheritance for dialogs, to a certain
degree. It just seems that for more complex cases this won't work as nice.

>
> If you _really_ want to create a CMyWindow class, you can always use
> aggregation.

In the case above, I'd have to assign to all the signal handlers in the
constructor. Ok, I think I have live with it, so it's not so elegant.

- Volodya


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk