[Qt-interest] question about mixing gui and non gui classess
Mihail Naydenov
mlists at ymail.com
Mon May 16 22:05:43 CEST 2011
Your question is hardly Qt related, these are design/patterns questions :)
Anyways, first the generic answer - do the way that minimizes interdependency
and maximizes specialization.
It is hard to tell if your first solution is a bad one. It has many
signals-slots but if these are not interdependent - like pure output
communication from the 3 engines to the UI, I believe its fine. But if the 3
work classes are also linked to each other and depend on each others execution,
well this could be messy, Is hard to tell from the outside... but may be then
you can consider refactoring these into one engine object that uses a thread
pool to do the work of the 3?
Adding a mediator class Temperature that manges *both* UI and backend hardly
solves anything IMOHO.
You become dependent on this glue class, and the design is harder to change. If
things need to be (or can be made) autonomous use signals and slots as much as
possible.
On the other hand, a class that wraps and aggregates some or all of the GUI or
backend classes into one, manages these (calling functions on them, private even
if needed) and then presents a simplified interface, I think it is worth it. The
inner engines do their specialized work, with simple desing, not caring to
present a full-featured interface, then an upper class, manages the mess of the
engines communications, but containing no work-logic on its own, and presenting
the simplest posible interface to the world. Same can be true for both UI and
backend classes.
So there you have it an opinion, mind you I am not a CS major :)
MihailNaydenov
----- Original Message ----
> From: franki <franki at franki.eu.org>
> To: qt-interest <qt-interest at qt.nokia.com>
> Sent: Mon, May 16, 2011 8:56:59 PM
> Subject: [Qt-interest] question about mixing gui and non gui classess
>
> Hi all,
>
> I have app which communicates with server to display temperature from
> different devices. Question is how to lay out classess which interacts with
> GUI and classess responsible for holding/calculating data. Let's say, I have
> 4 pages (widgets of QStackedWidget), each page is separate object (a class)
> that displays data and interact with user, next there are three objects
> (different classess) that are holding data, and exchanging it with different
> QThread that is running network-manager to get/send data from/to server
> So far I have such a layout:
>
> MainPages: public QStackedWidget - main class that has GUI pages,
> inside this class four other gui classess are created, and pointer for
> managing gui widgets (UI::MainPages ui) is passed to each class, each class
> is responsible for one page of QStackedWidget.
> Apart from this, there are three objects that inherits QObject (to be able to
> send signals) also created inside MainPages class, these just share and
> calculate data received from server.
> Now, when data arrives from server it first goes to one of three objects, it
> is calculated, and then it goes to one or more "gui" classess to display
> result.
>
> What is worrying me is that all these objects are not related to each other,
> thus all communication between them goes by signal-slot solution. I have more
> than 50 defined connections between these objects and it looks like a mess
> when I look at this.I would like to reorganize it in such a way:
>
> MainPages - creates main Temperature class (pointer for gui objects is passed
> to that class), Temperature class creates "gui" classess as a child objects
> (again pointer for gui is passed), plus classes to calculate data received
> from network-manager are created as children of Temperature class.
> Now, lots of data I need to display (after calculation inside Temperature
> class) can be passed to "gui" classess by simple function calls, and I think
> it's simpler and more organized in that way.
>
> The disadvantage of this approach (or at least I think so) is that I need to
> pass pointer to gui elements from MainPages class deep inside classess
> hierarchy, and to the classess that are only responsible for calculating
> data received from network-manager.
>
> But should that ever worry me?
> What is "blessed" way of laying out objects that are gui related
> and these that are only calculating data? And is it safe to pass pointer for
> graphic elements deep inside class hierarchy?
>
> best regards
> Marek
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list