I need some opinion on a problem I am facing now, appreciate any input. Thanks =).
I want to design a code architecture whereby the user interface is exposed by Manager singleton classes, for example, SceneManager. Managers typically manages a whole bunch of objects that are closely related. Often times the Manager is required to call some other class' member functions that are "internal" to the architecture.
For example I have a SceneManager which exposes the RemoveSceneNode() to, well, remove SceneNodes safely:
class SceneManager : public Singleton<SceneManager>{public: // finds the actual SceneNode and call SceneNode::RemoveChildNode() // before calling delete on itself. void RemoveSceneNode(String name);private: SceneNode* _mRoot; std::map<String, SceneNode*> _mSceneNodes;};
A possible SceneNode is as follows, but can introduce misuse.
class SceneNode{public: // Search _mChildren and remove the node // But putting this in public can introduce potential misuse, // like people calling this directly. void RemoveSceneNode(SceneNode* node);private: std::list<SceneNode*> _mChildren;};
A possible solution is to use friend class, but is this acceptable?
class SceneNode{// This design breaks OOP, but in this case is it acceptable?fiend class SceneManager;private: void RemoveSceneNode(SceneNode* node); std::list<SceneNode*> _mChildren;};
Yet another way is to do the search for child nodes inside SceneManager itself, but that also has other OOP issues as well as the need to access the private _mChildren list.
What could be a better design?