State Manager Questions

Started by
3 comments, last by caseyd 18 years, 8 months ago
I'm currently putting together a game framework for the development of 2D rpg's/arcade style games. I created a CMessageHandler as my most base class and am currently starting work on my state manager. I'm really still pretty new to the OOP approach of programming. Am I right in saying that my StateManager class should inherit from the CMessageHandler class or should it inherit from the CApplication class which inherits from the CMessageHandler? Should it inherit from anything at all? I know that these questions probably don't have a simple answer as it would really depend on the design. Any input would be most appreciated. [Edited by - caseyd on August 2, 2005 10:05:43 PM]
Advertisement
Very hard to supply an answer without a clear idea of the roles of those classes. If you're not sure when to use inheritance, I would avoid using it entirely to begin with. Then if the functions of certain classes overlap, or you need to be able to access a bunch of different classes in a similar way, then start thinking about inheritance and OOP.
I'm using a heavily modified version of the state manager design detailed here, the article itself is quite short but it should give you some ideas of how to approach designing your state management system.
Inheritance can be a hard thing to figure out. There are no definitive rules out there about what you should do, but there are definitely ways to tell if you're doing things wrong.

Just figure out what each class needs to do, and if you find a lot of commonality, or you find that you need to use an interface, then maybe you need inheritance. So, does your state manager need to handle messages? Should it have all of the functions of a message handler? Will some function need to send messages to the state manager without necessarily knowing anything about the state manager?

If you inherit something and never end up using anything from the base class, then obviously you didn't need to do so in the first place.
Thanks for the link. It was very helpful.

This topic is closed to new replies.

Advertisement