Re: [gtkmm] Design Question



Craig Slusher <ouslush columbus rr com> writes:

[...]

> If someone could please explain a common way of connecting the GUI
> pieces and the backend AddressBook class code together, I would
> greatly appreciate it. I like the idea of keeping each part of the
> GUI in separate headers so that I can easily edit each part of the
> GUI code.

I wrote a something about this on the gnomemm-list:

  http://mail.gnome.org/archives/gnomemm-list/2003-March/msg00024.html

Although I do think that having a class is too much for simple message
dialogs.

As for connecting the backend to the frontend, that's a general OOP
problem. On one hand, the frontend is supposed to sit on top of the
backend so it is OK to have the frontend contain instances of the
backend classes. On the other hand, you don't want to muddy the waters
more than necessary.

I've done it with the following pattern:

   main class contains:

     backend class 1
     backend class 2
     main window


   main window class contains:

     preferences window
     minor window 1
     minor window 2

Then the rest of the classes are "flat". This does raise the issue of
how the window classes contact the backend. Usually, I just make the
main class a singleton so that I can get to it with
Main::instance().some_method(), but this is just like a glorified
global pointer, really. Alternatively, one can pass a reference to the
main class to the constructor of the window classes, as you suggest.
It is more flexible, but also more tedious.

Similarly, preferences windows and minor windows needs to contact the
main window. Either they can go through the main class, or the main
window can pass them a reference when it constructs them.


Also, for most of my projects, the main class is so thin that I've
just merged it with the main window class.

Does this help? Comments?

-- 
Ole Laursen
http://www.cs.auc.dk/~olau/



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