I am currently trying to create a menu system for a game and cannot come up with any really healthy way to do this. There are several menu screens, each of which is non-trivial, so I would like to save them as separate classes. The main problem I encountered is the transfer of control between these menu screens.
I tried to build each of the screens as a singleton and call one screen from another directly, i.e. something like [[MainMenu instance] display]Objective C. This is a bit messy because (1) I have to write the same template code for each of the menu screens and (2) the classes become dependent on each other, sometimes I have to code around circular dependencies, etc. .
I was thinking about making the classes completely static in order to get around instance management (which is a bit more in this case, since this is actually just one instance of each screen). But it also looks pretty ugly, especially with Objective-C, which should "fake" class variables by declaring them static.
Then I thought of some βmanagerβ class that would instantiate and pass the control, but I'm not sure that introducing an additional class will solve the problem, especially if this class should be called Manager :-)
I should note that I have a working system, it is just not very pleasant. By this, I mean that there is duplication of code, if I am not careful what it might hang, and so on. Any ideas? I know this is unproven, so the discussion is likely to be a brainstorm, but I'm still interested in ideas, even if they don't solve my problem.
Update: Thanks to everyone for the ideas. What I did at the end:
I reworked the contents of the menu (buttons, graphics, etc.) to fit under one interface called ScreenView. This is a common interface that looks like this:
@protocol ScreenView
- (void) draw;
- (BOOL) handlesPoint: (CGPoint) p;
- (void) appearWithAnimation;
- (void) disappearWithAnimation;
- (BOOL) hasFinishedAnimating;
@optional
- (void) fingerDown;
- (void) fingerUp;
@end
, , , , .. , , . V MVC.
, . (, C MVC.) , . , .
, , . , Im . , .