How to (fallowing dependency inversion principle) implement class "MainWidgetDisplay" to make it independent from IStorage and to be able to connect with IStorage's signals and slots?
If you want to implement MainWidgetDisplay independent of IStorage you could well do it. One simple trick is to check your dependency is make sure that you don't include IStorage.h file from MainWidgetDisplay implementation and header files either directly or indirectly. So if you want to connect signal and slots between them, the signal and slots connections SHOULD NOT be made from either off these two classes. The signal and slots connections between them should be made by some other class generally by the parent object class implementation (as in below example)
//Example SomeClass (parent objects's class)
#include "SomeClass.h"
#include "IStorage.h"
#include "MainDisplayWidget.h"
void SomeClass::ShowMainWidget(void)
{
IStorage* storage = new IStorage(this);
MainDisplayWidget* widget = new MainDisplayWidget(this);
// IStorage Signal >>>>>>>>>>>>>>>> MainDisplayWidget Slot
connect(storage,
SIGNAL(IStorageSignal
(const QString)), widget,
SLOT(MainDisplayWidgetSlot
(const QString)));
// MainDisplayWidget Signal >>>>>>>>>>>>>>>> IStorage Slot
connect(widget,
SIGNAL(MainDisplayWidgetSignal
(const QString)), storage,
SLOT(IStorageSlot
(const QString)));
}
//Example SomeClass (parent objects's class)
#include "SomeClass.h"
#include "IStorage.h"
#include "MainDisplayWidget.h"
void SomeClass::ShowMainWidget(void)
{
IStorage* storage = new IStorage(this);
MainDisplayWidget* widget = new MainDisplayWidget(this);
// IStorage Signal >>>>>>>>>>>>>>>> MainDisplayWidget Slot
connect(storage, SIGNAL(IStorageSignal(const QString)), widget, SLOT(MainDisplayWidgetSlot(const QString)));
// MainDisplayWidget Signal >>>>>>>>>>>>>>>> IStorage Slot
connect(widget, SIGNAL(MainDisplayWidgetSignal(const QString)), storage, SLOT(IStorageSlot(const QString)));
}
To copy to clipboard, switch view to plain text mode
This way MainDisplayWidget is independent of IStorage, and also IStorage is independent of MainDisplayWidget.
Bookmarks