PDA

View Full Version : MVC and complex objects


kribba
10-18-2007, 01:47 PM
A question about using the MVC pattern. As far as i understand it an application should have one view, one controller and one model. And different examples i have looked at have implemented this smoothly and easily.

But when creating games, it seems that the objects get more complex. Say for example that there are different bugs flying around on the screen and the user should try and click on some and avoid some. The view consists of the graphics of the bugs, animation, and user input listeners. How will the controller work?

Should every bug have it's own controller? Or should every click be funneled into one controller class that decides what should happen?

Hope somebody has an answer :)

Flash Gordon
10-21-2007, 04:57 AM
You can totally have more than 1 view. That's the cool thing about MVC. And each view could have its own controller or they could share.

In your case, each bug could be a view.

kribba
10-22-2007, 02:10 PM
thanx :)
Guess everything depends on what is smoothest to work with later on.

Also wouldn't having just one controller that handles everything break the idea of having encapsulated objects too? But at the same time it feels abit over the top to have one view, controller and model for everything on the screen

Flash Gordon
11-07-2007, 09:17 PM
I don't think so. I think it is usually 1 controller per 1 type of view.

jsebrech
11-08-2007, 01:28 PM
For example, in a drawing program your menu/toolbox is a controller, all your image windows are views, and the actual data for the images are the models. Multiple views can exist for the same model (image), but in the end a single controller manages all the views / models.