From d2942dd1f14fe18abc8b4114c06e649025b8aa72 Mon Sep 17 00:00:00 2001 From: Ratstail91 Date: Tue, 30 Sep 2014 09:20:33 -0700 Subject: [PATCH] Getting my thoughts down in writing, concerning managers. --- Manager-Pseudo-Interface.md | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Manager-Pseudo-Interface.md diff --git a/Manager-Pseudo-Interface.md b/Manager-Pseudo-Interface.md new file mode 100644 index 0000000..84fc48d --- /dev/null +++ b/Manager-Pseudo-Interface.md @@ -0,0 +1,45 @@ +## Concept +Usually, whenever you have multiple classes with similar code, you would inherit one from the other, or both from a common ancestor. Currently, AccountManager and CharacterManager (and hopefully RoomManager) share all of their method names, so ideally I'd write an interface class. However, since each requires a different number of parameters to some of these methods, I can't do that. Instead, I'll list the methods here. + +## Common *Manager Methods +An ellipsis (...) indicates a list of variable parameter types, and T is the type handled by the manager class. + +``` +//basic management methods +Create(...) +Load(...) +Save(int uid) +Unload(int uid) +Delete(int uid) +UnloadAll() +UnloadIf(std::function)> fn) + +//accessors +T* Get(int uid) +int GetLoadedCount() //number of elements in memory +int GetTotalCount() //number of elements in database +std::map* GetContainer() //OO Breaker, I couldn't fix this :( + +//database hooks +sqlite3* SetDatabase(sqlite3* db); +sqlite3* GetDatabase(); + +//The constructor & destructor are default, and private +//The singleton template class is declared friend +``` + +## Theoretical Solution +The only technical drawbacks are the parameter lists of Create() and Load(). Otherwise, a templated *Manager class is perfectly viable. Here's my outline for it. + +``` +template +class Manager : public Singleton> { +public: + //list all above methods as virtual except Create() & Load() + //some methods, particularly those requiring database access, are declared pure virtual +private: + std::map container; + //etc. +}; +``` +There's no guarantee this would be 100% perfect, since the RoomManager class will likely require other systems, like room management, etc. Nonetheless, this is still an OK template to follow. \ No newline at end of file