I wonder if I can copy your flowchart and import them to www.draw.io
Sorry, normally you can share the graphs themselves in one of the graph formats supported, but I just exported them as images and didn't kept originals. Shouldn't be too hard to recreate them though if you want to. It took me like 5 minutes to make them.
Just a note so you don't get the wrong impressions. These charts are only meant to represent dependencies, not which code calls what and whether to use connections or something else. You can actually implement the bad and the good model using the same tools, it's just a matter of arranging them.
For example, this is a simple one way dependency:
struct Data { ... };
class Dialog
{
public slots:
void doSomething(const Data& data)
{
emit somethingHappened(data);
}
signals:
void somethingHappened(const Data& data);
};
class MainWindow
{
MainWindow()
{
connect(&dialog, &Dialog::somethingHappened, this, &MainWindow::doSomething);
Data data;
dialog.doSomething(data);
}
void doSomething(const Data& data)
{}
Dialog dialog;
};
If you delete Dialog then MainWindow won't compile, but you can delete MainWindow and Dialog works without any changes. This is a one way dependency that would be represented like this:
[image: y4md6igANcwE44KUV8o4S6AifBgrUkE2QK-OAXWmMWj4tnoIJ9TLbE892ZiKdOES8CvwlfwA8At_GTRjUTmFCPIziNvIIzM8chWGZGB2Tx-p2HaWnOsEVuZZoSUbbQtGVRnxpbBbO4wGuU5w1jSj_sWyUJhNkVBzTDJ6VhV--X7nNJJKnQAaZS7zLlNl7x3qBq1?width=321&height=31&cropmode=none]
But you can achieve exactly the same functionality with bad dependency management like this:
struct Data { ... };
class MainWindow;
MainWindow* global;
class Dialog
{
Dialog()
{
connect(this, &Dialog::somethingHappened, global, &MainWindow::doSomething);
}
public slots:
void doSomething()
{
emit somethingHappened(global->data);
}
signals:
void somethingHappened(const Data& data);
};
class MainWindow
{
MainWindow()
{
global = this;
dialog.doSomething();
}
void doSomething(const Data& data)
{}
Data data;
Dialog dialog;
};
It does exactly the same but creates circular dependency. You can't delete one class without at least modifying the other. You also have a class declaration chicken and egg problem so it's actually hard to make this code compile. This would be the two way, or, in case of more classes, a circular dependency:
[image: y4mu2-eLWOianc8v1xQbC2rh_c3NLbzZ1KJ5f81CWTXNqae4alLQzw_u4aPYeL4g8tRj0AXRBHykeQ8WxX8FOumRMi1RS7QwaITh-ulfKClbl6X0RzwrRQPqUg6ubRbSYgjt8pCQwzLIgp5CDu9oTyjoEdFl1NzaemmEMS0zhsOPn4KeqDANe95yO_JC8ht-lpA?width=321&height=31&cropmode=none]
But, as you can hopefully see, it doesn't have anything to do with oop or any other buzz word. Both use the same tools - classes, signals and connects. It's just a matter of code layout and sitting with a pencil and a piece of paper to draw up dependencies before starting to code.