0

I'm developing a game and inside I have a class called StageViewController. I noticed that code inside is becoming very very long and dull. In this class I have controller about gesture, position, animation and it's not easy use static class or singleton class to clean this class. Is a possible solution to use others viewcontrollers inside this StageViewController to simplify the code? Example: If in my game I should make an entry of an object that I should color, can I use another viewcontroller (with another class) to make my code inside StageViewController more simplify?

If you have any suggestion for me or link to read you can make me happy ;-)

rmaddy
  • 314,917
  • 42
  • 532
  • 579
cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241

1 Answers1

1

Typically this indicates that you're storing model information in the view controller. The view controller should only keep track of how to display information. You should move the actual state of the game into model classes. These model classes inherit from NSObject, they are not view controllers.

In a well designed model-view-controller system, you should be able to run your entire game without knowing what the display looks like. Your model should be able to take inputs, update the game state, and provide outputs, regardless of how or whether that information is actually displayed. This kind of thinking improves reusability, and also reduces the complexity of your view controllers.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • yes but the best solution in your opinion is to use the model classes as static classes (NSObject)?; for example: use it to check a score point, or use it to check if an element is dragged in a correct position? is this the correct usage? Inside these classes can I use classes methods? (I mean method that use "+" in declaration) – cyclingIsBetter Oct 30 '13 at 18:04
  • NSObject doesn't mean they are "static classes." You can create your model objects at startup time and hand them to the view controllers, or you can use singletons. If we were talking about as "space ships flying around" game you might expect there to be "Ship" objects and each would have a location. And as those locations changed, then the views would update accordingly. If something destroyed a ship object, the view controller would remove the corresponding view. Etc. – Rob Napier Oct 30 '13 at 18:18