June 20, 2011

MVC Again

I've been slowly starting to see how useful the ideas from MVC really are. Strict MVC isn't a very good implementation but the idea of proxy models is very useful. For example, read a set of data from a database would be the controller. Load the data and store the data into a list of information, that would be the model. Take the model and sort it with mappings to the original data, that would be the proxy model. Display the sorted data to the user inside of a table, that would be the view. As you can see by isolating the model from the view you never need to directly modify the model, instead you can use a proxy model to change the mapping of the data into a sorted version for the view. Separating this means that you can sort the data on the fly without having to actually modify the underlying data. If you want to remove a row after you have sorted it, you can map back to the original without having to find out where it was stored. It is kind of neat, but something nice to have with MVC. This idea can be applied in a few places in games which is why I mention it. I'm not saying use MVC for games, but you can easily take concepts from it and use it to effectively solve problems with it.

No comments :

Post a Comment