Does it make sense to put everything in a subclass of QApplication?

In my plugin architecture, plugins should have access to all the main components of the application, for example. in the main window, widget settings, settings, tray icon and several global immutable variables.

Since the application is a global single, it directly subclasses it and makes all of these components members of the application. That way, I can easily access them from all over the world. 2. I can phase their API for plugins 3. Naturally, the components are members of the "application".

However, reading SO lessons on singles and globals, he feels like a bad design, but otherwise I will have to implement the main facade and pass it on, which is also a bad design, and finally less straightforward.

+4
source share
3 answers

I think it is best to distinguish between IS A and HAS A (inheritance versus containment) in this case.

The plugin is not a QApplication. It uses QApplication. I see no reason to make it a subclass. Just give it a pointer or a link to QApplication.

This is one of the things that the observer pattern does for you, objects (QApplication) have links to their observers (plugin). You can also use this in a symmetrical way.

But using an observer pattern is not always necessary. The main thing is that your plugins have a link or pointer to a QApplication instance.

+2
source

. .

, , , , . , , .

.

+1

, , , . KDE , , Conltroler , , -. (KDE QT, , KDEPlugin QT). PS: , " ".

0

Source: https://habr.com/ru/post/1657036/


All Articles