scarecr0w132
1st January 2015, 06:47
Hello,
I have a class Document and a class Form. I want Document class to have access to form class.
These are my two approaches -
Approach 1:
Approach 1 project found here. (https://drive.google.com/file/d/0B3L3m1Bl8tqSYTU3Z3M5TmJwRWs/view?usp=sharing)
mainwindow.cpp
...
// Inside MainWindow init method
Document* document = new Document();
setCentralWidget(document->currentForm());
...
document.cpp
...
Document::Document()
{
form = new Form();
}
Form* Document::currentForm()
{
return form;
}
...
Approach 2:
Approach 2 project found here. (https://drive.google.com/file/d/0B3L3m1Bl8tqSWkdaVnBoQk9CQlE/view?usp=sharing)
mainwindow.cpp
...
// Inside MainWindow init method
Form* form = new Form();
setCentralWidget(form);
Document* document = new Document();
document->setCurrentForm(form);
...
document.cpp
...
void Document::setCurrentForm(Form* currentForm)
{
form = currentForm;
}
...
which design should I use?
I want to follow Qt's design patterns.
Thanks
I have a class Document and a class Form. I want Document class to have access to form class.
These are my two approaches -
Approach 1:
Approach 1 project found here. (https://drive.google.com/file/d/0B3L3m1Bl8tqSYTU3Z3M5TmJwRWs/view?usp=sharing)
mainwindow.cpp
...
// Inside MainWindow init method
Document* document = new Document();
setCentralWidget(document->currentForm());
...
document.cpp
...
Document::Document()
{
form = new Form();
}
Form* Document::currentForm()
{
return form;
}
...
Approach 2:
Approach 2 project found here. (https://drive.google.com/file/d/0B3L3m1Bl8tqSWkdaVnBoQk9CQlE/view?usp=sharing)
mainwindow.cpp
...
// Inside MainWindow init method
Form* form = new Form();
setCentralWidget(form);
Document* document = new Document();
document->setCurrentForm(form);
...
document.cpp
...
void Document::setCurrentForm(Form* currentForm)
{
form = currentForm;
}
...
which design should I use?
I want to follow Qt's design patterns.
Thanks