Hello everybody..
I'm here again looking for some advices, so thank you before everything.
I have some collections in my main application class, but I need to retrieve them from other different classes and I would like to know a good way to achieve that. It looks like this:
// This class handles the collections and is responsible of setting up them
private:
DualCollection<Unit> units; //Internally implemented as two QHashes with QString as key type. Don't think it really matters.
DualCollection<GameItem> items;
// So on.
};
class RosterUnit {
public:
void RosterUnit(); // This method need to get a read-only Unit and parse some information. It also needs access to some items
};
class ObjectAction {
public:
void doAction() = 0; // Some subclasses will eventually need access to some information like Units or Items
};
class App : QApplication {
// This class handles the collections and is responsible of setting up them
private:
DualCollection<Unit> units; //Internally implemented as two QHashes with QString as key type. Don't think it really matters.
DualCollection<GameItem> items;
// So on.
};
class RosterUnit {
public:
void RosterUnit(); // This method need to get a read-only Unit and parse some information. It also needs access to some items
};
class ObjectAction {
public:
void doAction() = 0; // Some subclasses will eventually need access to some information like Units or Items
};
To copy to clipboard, switch view to plain text mode
In fact there are probably other two classes that need to retrieve some information.. I was thinking to use the Singleton pattern with the application class and provide functions like getItem(const QString& key), getUnit(...) and so on, but I'm not sure if it's a good choice. I have read some disadvantages that apply to global variables and singletons like they are hard to debug because they can be modified in the whole application, but it does not apply here because I will provide only a public interface for reading.
What do you think?
Thank you very much!
Bookmarks