Hi everybody!
I just registered here but I have been reading some articles in this page and the whole Internet.
I'm rewriting an application using C++/Qt and, although my application is working fine, I don't think i'm using a good method.
If it helps, it is an open source project with a page in Google Code:
http://code.google.com/p/yalb/source/browse/#svn%2Ftrunk%2F%20yalbgameeditor
Because my project has three applications, I use a polymorphic class (StructManager) to provide generic methods for adding, removing and updating my own structs. For the first of the three applications, I created a second class (StructEditor) that inherits from StructManager and overrides its methods so they perform additional actions. Basically with StructManager I add the structs to a key-based collection (QHash) and with StructEditor I add them to the UI.
Here is the problem: I need access to about 12 UI Objects in StructEditor plus other 6 Collections in StructManager, and right now I am using pointers as public members so they can be assigned outside the class. I'm sure this is not the best way to do this and I'm looking for a better one. I have some options but they have some drawbacks:
1. Make pointers private and assign them through the class constructor, but the constructor would have at least 19 arguments (12 UI Objects pointers + 6 Collections pointers + 1 parent pointer) and I don't think it results in an easy readable code.
2. The same as the first option but creating a new struct with every parameter I need and pass it through the constructor. Something like:
1 2 3 4 5 6 7 8 9
|
struct arguments {
someType *parameter1;
otherType *parameter2;
...
};
// In StructEditor Class
StructEditor(arguments args);
|
3. Create another polymorphic class which is inherited by the UI class and implement methods like "addRow", "getRow" and so on. The problem is that I need to get and set many data to the UI objects, so I would have to create many methods and I would have to rewrite this code for at least other of the three applications (that is what I'm trying to avoid/reduce)
I have read some about singletons, but I only need to share these variables with another class, so I think they are unuseful here.
For better understanding, please refer to:
http://code.google.com/p/yalb/source/browse/trunk/%20yalbgameeditor/structeditor.h
http://code.google.com/p/yalb/source/browse/trunk/%20yalbgameeditor/structeditor.cpp
Thanks and excuse my English.
Greetings!