better design pattern
-
I want to know which type of design patter would you use and which would you think is best.
IG it will be quite long but instead of making many different questions, I will be doing in one.
Suppose, We will be using some database with some tables
I will try to simplify as much as I can
Let's StartUser_Email Table:
id name Email 1 Cute Mute boi@email.com 3 Hes Mos hey@email.com User_post Table:
id post 1 welcome 1 dope Which approach would be best for connection of these data base and fetching all datas:
Taking these in consideration:- Design Pattern
- Code Readability
- Maintenance
- Memory Footprint
- Faster
- Folder Structure
Let's suppose some scenario:
- Name will be in drop-down menu in multiple widgets, lets say 10
- User can post post and other data through different widgets. (Lets think that there are more than one 20 columns of data with separate insert , update and delete widget)
How to cope with this situation? I will mention my way, and I am very pleased to get it's bad sides.
Method 1:
creating widgets like
updateusername.h , updatepost.h , createpost.h, updateemail.h and so on for all
And implementing them differently like:- Opening connection in main -> main.cpp or any other file that will execute at first
- Getting connection and fetching same thing repeatedly over and over for multiple files.
Suppose, we want to fill all emails in QComboBox in all of files,
So creatingfillEmail()in each file we have
Method 2:
- creating widgets like mentioned in method one
- Creating Database Controller class for every table
Likeuser_email.h
class userEmail{ public: void updateEmail(int id, QString newEmail); void updateName(int id, QString newName); QVector<QString> getAllEmail(); QVector<QString> getAllName(); private: int id; QString name; QString email; };and same for all tables and including that class in all file that we are gonna use this like
updateemail.h#include"user_email.h" // all class declaration----- private: userEmail thisOne; // and in updateemail.cpp, use functionsIf
updatename.his another file using this database, we include in same way and do rest of it.
Method 3:
Almost same as method 2,
but creating all database controllers as SINGLETONS, (may be less memory footprints? 🤔)
I can mostly think of these three patterns only.
I would be happy to get links and study materials if you feel I am not that mature with any of idea.
Ah!, It became quite long than expected.
-
Hi,
Did you consider using QDataWidgetMapper ?
-
Hi,
Did you consider using QDataWidgetMapper ?
-
I would say a bit too complicated.
You seem to be ready to store a lot of data in each of your widgets rather than take advantage of the model view approach.
-
I would say a bit too complicated.
You seem to be ready to store a lot of data in each of your widgets rather than take advantage of the model view approach.
@SGaist
Yes, I was waiting for something like this.
I am not really making application but want to know how to cope with something like this. It was in my mind for long time so I asked about it.
The last simple application I designed had these problem so I thought it would be much better to know about it before actually making another application -
I would say a bit too complicated.
You seem to be ready to store a lot of data in each of your widgets rather than take advantage of the model view approach.
Yes I am also eager to know about this question 😀😀
-
@SGaist
Yes, I was waiting for something like this.
I am not really making application but want to know how to cope with something like this. It was in my mind for long time so I asked about it.
The last simple application I designed had these problem so I thought it would be much better to know about it before actually making another applicationWith a more detailed description about what your application will be about, it would be easier to discuss.
-
With a more detailed description about what your application will be about, it would be easier to discuss.
@SGaist
Oh ! It's been long since last time I was in this forum.
You can think this application as application where users can fetch/post/export/update/delete data which are stored in different tables in database.
Suppose let's say about all "fetching" here (getting list of datas and filling in combobox, auto filling datas in update pages, showing datas in tableviews and things like these)I had mentioned methods in the previous post. I would like to get your views on which method is efficient than others and consume less resources.
Is it good to load all data in constructor in every pages or create a controller and use that in different pages as needed?
Next one is If I have database mentioned above "user_email" Should I create a database page with functions likegetName(QString email), getEmail(QString name), updateName(QString previousname), getAllDetails(QString name), deleteData(QString name), getTotalCount(), insertData(name,email)
or should I implement these on specific widgets as needed in that widget.These fetched data could be used in different widgets and filled in combo boxes and other widgets as needed.
I had created one application. That used to fetch all data in constructor and it makes application load time nearly 30 seconds on some low end computers. So I feel like I should load data only when the widget is opened/shown. Which approach of data loading should be used?
-
When data loading is slow, lazy loading is used so it only impacts on use.