Model-View-Controller Pattern: Encapsulating logic and graphics in the same class?
-
Alright, so I realize that the MVC is the "responsible" design pattern, but it seams to make things more complicated and I just cant wrap my head around it. I'm currently programming a maze game for the Iphone, now according to the MVC I store the maze grid data in the model class, iterate over said data in the view-controller which then draws said data onto the view (please correct me if I'm wrong). When I think of an object orientated programming architecture I always think of how the objects work in real life. In my observation real life object contain their graphical information too. Would it be a crime against all programming gods if I just included my maze grid logic in the view class, so that I can draw data while it being generated? It would also make everything much more compact and give me a better overview? Thanks!
-
Answer:
Would it be a crime? No. Would it land you in MVC jail? Maybe. If the logic you want in the view layer is how to *present* the data, you're in the clear. That's totally what the view is for: show the user stuff. It's perfectly acceptable to have logic in your views, as long as the primary purpose of the logic is presentation of data from a model. Compactness isn't the point of MVCâit's being able nimbly add new features and react to problems quickly. Occasionally you "denormalize" or crunch things together to squeeze more speed out of your application, but that's a delicate balance you'll need to manage on your own. ;)
John David Anderson at Quora Visit the source
Related Q & A:
- How to call Controller from View?Best solution by Stack Overflow
- Is it correct to extend a bean class and write a class which holds logic to populate the bean we extend?Best solution by stackoverflow.com
- How to access the model from the controller in zend?Best solution by stackoverflow.com
- How to open a partial view from controller as a Jquery Mobile dialog?Best solution by Stack Overflow
- If a person was going to teach a yoga class to some people with learning disabilities, what is the best model of teaching?Best solution by reddit.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.