After reading from many different sources, I am very confused about how View and Model should communicate in the MVC pattern. To my understanding, the accepted answer of this post and this article from Apple are saying the communication of the two should be done through controller. While the MVC page in Wikipedia, the ASP.NET MVC page, and this article in MSDN are showing there is a direct association between View and Model. So according to the answer in here, what the article from Apple is referring to is actually MVP not MVC then? Thank you for any help!!
There is more than one answer.
Eventually you can do whatever you thing suits your needs.
I use a controller + ViewModels to connect to the view.
The view never use the model. just what the controller gives him.
There is a nice explanation of all models in steven sandarson book, Page 49
(variation on MVC).
Related
When I look at MVC diagrams I have this objection: why Controller is pictured facing user and View is hidden somewhere behind?
In my opinion user sees and interacts with View (this is what he sees in browser) and via View user "talks" to Controller, so why Controller is first in line?
Also, shouldn't diagram be shown like tower structure (instead of triangle):
View -allows user talking to- Controller - to- Model (on the bottom) - then (feed)back to- Controller -adjustment made to- View
When I see diagram with Controller facing user, I always have this strange picture of user, with a MVC diagram in one hand and screwdriver in another, popping computer's box open and looking for a Controller to get MVC started.
It's really unfortunate that most articles and books still use such useless diagrams to represent MVC. A more useful diagram for MVC is actually a UML sequence diagram like Dino Esposito uses on his book Microsoft .NET: Architecting Applications for the Enterprise
Secondly, as you point out, most MVC articles and books have not been updated to describe how MVC is applied nowadays in web applications and still talk about MVC as it was originally envisioned 20+ years ago.
The Esposito book that I mentioned has a really good chapter about this where he describes how MVC (as originally described) is dead and we should now be focusing in modern variations of it like Model2, Passive View, and Supervising Controller. I've got a review of this chapter on my blog that you might find useful.
After doing some reading on the Model View Controller pattern it seems that the pattern is implemented quite differently in web frameworks vs desktop frameworks. With web based MVC frameworks the view and model never communicate directly. They can only communicate with the controller. But in desktop implementations, it seems that the view and model can communicate directly which doesn't make sense to me. That would seem to defeat the purpose of MVC of having separate, clean, isolated layers. Plus, what does the controller do if the view and model communicate directly?
Here is a diagram from Wikipedia illustrating MVC.
Model-View-Controller
It's a funny thing that I wrote recently an article on my blog about the different implementation of the MVC concept in web frameworks.
You can read it here.
also there is Presentation-abstraction-control
I found this article that seems to best explain the issue. http://andrzejonsoftware.blogspot.com/2011/09/rails-is-not-mvc.html
It appears that there are really two architectures going by the same name: MVC and Model2.
I've recently discovered that MVC is supposed to have two different flavors, model one and model two. I'm supposed to give a presentation on MVC1 and I was instructed that "it's not the web based version, that is refered to as MVC2". As the presentations are about design patterns in general, I doubt that this separation is related to Java (I found some info on Sun's site, but it seemed far off) or ASP.
I have a pretty good understanding of what MVC is and I've used several (web) frameworks that enforce it, but this terminology is new to me. How is the web-based version different from other MVC (I'm guessing GUI) implementations? Does it have something to do with the stateless nature of HTTP?
Thanks,
Alex
It appears that MVC1 (model1) did not have a strong break between the controller and the view where as in MVC2(model2), these concerns were separated.
See if this gives you any more insight: MVC1 and MVC2 discussion
More InformationJust a little more
I Think this is the main difference between MVC1 andMVC2:
The hallmark of the MVC2 approach is the separation of Controller code
from content. (Implementations of presentation frameworks such as
Struts, adhere to the MVC2 approach). But for MVC1 did not have a
strong break between the controller and the view.
Model 1 Architecture: - Here JSP page will be responsible for all tasks and will be the target of all requests. The tasks may include authentication, data access, data manipulation etc. The architecture is suitable for simple applications.
Disadvantages: – Since the entire business logic is embedded in JSP chunks of java code had to be added to the JSP page.
For a web designer, the work will be difficult as they mite face problems with business logic.
The code is not reusable.
Model 2 Architecture : – The servlet act as the controller of the application and will be target of every request. They analyze the request and collect data required to generate response to JavaBeans object that act as model of the application. The JSP page forms the view of the application.
Advantages: – Reusability
Ease of maintenance.
I am trying to migrate to zend framework. Should each webpage be a Controller or an action.
What is the advantage of having multiple actions. Can they talk to each other? and whats the best use of Action helpers and View helpers.
Please guide me on how to start on the framework.. thanks
You can use a new controller for each page or define multiple actions on the same controller to render your pages. I choose to use defferent action from the same controller to display variuos pages. Using multiple action on the same controller allows you to put some code in che constructor of the controller that is executed for each action. For example i have a controller for all the pulic pages of a website and a new controller for those pages that are reserved to registered users. In the constructor for the controller dedicated to registered user i do the check for authentication.
You should check that page about MVC applications, It's not precisely related to Zend. But you seems to be asking what a MVC Design Pattern is.
You got to create a controller for each of your site's pages. If any page interacts with db, you should also create model for that page. Also you should create view for each of your page.
If you have no idea about MVC, you can read this:
MVC
Those links are from Zend Framework manual.
Do not afraid and click - read the Introduction chapters - you will have all answers. ;-)
View helpers
Action helpers
Action Controllers
First get a sound understand of MVC Framework:
Understanding MVC Architecture from its Origin (part I)
http://learnnewprogramming.com/blog/understanding-mvc-architecture/
What are your favourite patterns for writing a controller?
This is rather a tough question as MVC is applied differently in different contexts. For example, for a desktop GUI, you might have listeners for event notifications of view changes but such behavior typically isn't used for Web forms (AJAX is changing this).
For the Web, you generally have:
Model: business logic
View: presentation logic
Controller: application logic
The controller should generally be minimalistic and if you find yourself pushing display information or business rules in it, there's probably a design flaw somewhere. Classic examples of such flaws in the controller are building HTML (view) or accessing the database directly (model).
I've written up a more thorough description of MVC on my O'Reilly blog. I have concrete examples there which can help explain things a bit more in depth.