Should i use mvp or mvc
The presenter is responsible for binding the model to the view. Complex views may have multi presenters. If not, do not be discouraged patterns are powerful tools that can be hard to use sometimes. One thing to remember is that a pattern is a blueprint and not an out of the box solutions. Developers should use them as a guide and modify the implementation according to their problem domain. Developers User Experience Business Teams.
Written by Anh Dang Follow. More From Medium. Manas: A high performing customized search system. Pinterest Engineering in Pinterest Engineering Blog. Stein Janssen in Level Up Coding. Make your Kubernetes cluster bulletproof. Dmitrii Evstiukhin in The Startup. Parker Shepherd in The Entrepreneur Life. Community Bot 1 1 1 silver badge. Brian Leahy Brian Leahy I mostly seen the opposite, with the Presenter launching both the Model and the View. Well, the View may launch the Presenter too, but that point is not really the most distinctive.
What matters the most happens later during lifetime. You may want to edit your answer to explain further: Since the View does not know about the Controller, how are user actions, which are performed on the 'visual' elements the user sees on screen i. But in MVP pattern, when the application loads for the first time , isn't the presenter is responsible to load the first view? Like for example when we load the facebook applicaiton, isn't the presenter responsible to load the login page?
You may want to edit your answer to explain how this makes it a 'decoupled' system, given this link. Hint: You may find it hard. Also, unless you think the reader will happily accept they've been computing wrong their whole life, you may want to elaborate on why actions go through Controller first in MVC despite the user interacting with the 'visual' elements on the screen i. This Is clearly wrong They don't even know other one exists.
The controller is the glue that holds them together — MegaManX. I agree with Ash and MegaManX. The problem I see is the input to the Controller and its link to the View. Normally the user interacts with the view, so the View should be linked towards the Controller.
Holmes Queen 2 2 gold badges 6 6 silver badges 17 17 bronze badges. Ali Nem Ali Nem 4, 1 1 gold badge 38 38 silver badges 37 37 bronze badges. Basically what you're trying to say is that the controller micromanages the view logic? So it makes the view dumber by presenting what happens and how on views? Radu, No, it does not micromanage, that is what the presenter does by making the view passive or dumb — Ali Nem.
In a proper MVC, the view invokes functionality on the controller, and listens to data changes in the model. The view does not get data from the controller, and the controller should NOT tell the view to display, for instance, a loading indicator. A proper MVC allows you to replace the view part, with one that is fundamentally different. The view part holds view logic, that includes a loading indicator.
The view invokes instructions in controller , controller modifies data in the model, and the model notifies its listeners of changes to its data, one such listener is the view. It separates an application into the following components: Models for handling data and business logic Controllers for handling the user interface and application Views for handling graphical user interface objects and presentation To make this a little more clear, let's imagine a simple shopping list app.
Model-View-Presenter The model is the data that will be displayed in the view user interface. The view is an interface that displays data the model and routes user commands events to the Presenter to act upon that data.
The view usually has a reference to its Presenter. It should rather be business logic that retrieves or manipulates a Model. For instance: If you have a database storing User in a database table and your View wants to display a list of users, then the Presenter would have a reference to your database business logic like a DAO from where the Presenter will query a list of Users. If you want to see a sample with simple implementation please check this GitHub post A concrete workflow of querying and displaying a list of users from a database could work like this: What is the difference between MVC and MVP patterns?
Rahul Rahul 2, 2 2 gold badges 24 24 silver badges 39 39 bronze badges. A great article on the differences is here.
Brett Veenstra Brett Veenstra Model updating the VIew. And this still is a decoupled system? MVP designs have the Presenter access the model and interact with the view. Matt Mitchell Matt Mitchell If you honestly think, that topic was about. NET framework, then it is like hearing "the internet" and thinking it is about IE.
Pretty sure the question has evolved significantly from when it was first asked back in Additionally, looking back at my answer and this was 4 years ago so I have not a lot more context than you I'd say I start generally and then use. MVC on other hand changes completely the game because the request gets intercepted by controller class before page is loaded, the business logic is executed there and then at the end result of controller processing the data just dumped to the page "view" In that sense, MVC looks at least to me a lot to Supervising Controller flavor of MVP enhanced with routing engine Both of them enable TDD and have downsides and upsides.
Nikola Malovic Nikola Malovic 1, 12 12 silver badges 24 24 bronze badges. Pedro Santos Pedro Santos 2 2 gold badges 15 15 silver badges 22 22 bronze badges. James Roeiter James Roeiter 1 1 gold badge 9 9 silver badges 22 22 bronze badges. Hibou57 Hibou57 6, 4 4 gold badges 46 46 silver badges 50 50 bronze badges. Jeremiah Flaga Jeremiah Flaga 4, 2 2 gold badges 20 20 silver badges 19 19 bronze badges. This is an inaccurate answer. Do not be misled.
The MVC image is inaccurate or at best misleading, please do not pay any attention to this answer. Jay1b What MVC do you think is "correct"? This answer is about the original MVC. What do the arrows mean?
Clive Jefferies Clive Jefferies 1, 12 12 silver badges 26 26 bronze badges. I have downvoted, because afaik the model does not know anything about the view in MVC and there is not able to update it directly as you write. Look at MVC on Wikipedia, that is exactly how it works. Whether readers like it or not, plenty sources that can be found by googling state that in MVC the view subscribes to updates on the model. If you don't like that, then go complain on those articles, or cite which 'bible' you think is the sole legitimate source, instead of downvoting answers that just relay the other info available out there!
The wording could definitely be improved, but it's true that the view subscribes to changes in the model in MVC. The model does not need to know the View in MVC. I hope this helps better. Rahul 2, 2 2 gold badges 24 24 silver badges 39 39 bronze badges.
The presenter calls the view directly for updates to the UI part. Model which contains business logic is called by the presenter and no interaction whatsoever with the view. So here presenter does most of the work :. Chinmai Kulkarni Chinmai Kulkarni 1 1 silver badge 4 4 bronze badges.
MVC vs. In MVP, Views have no logic and we should keep them dumb as possible. On the other hand, Views in MVC may have some sort of logic. This allows mocking the View in unit tests. Mostafa Wael Mostafa Wael 2 2 silver badges 8 8 bronze badges. View event binding will be implemented in the Presenter from a view interface. Controller is the initiator and it decides which view to render. Pros: Emphasis on Single Responsibility Principle High level of testability Cons: Sometimes too much workload for Controllers, if try to render multiple views in same controller.
The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta.
Now live: A fully responsive profile. Linked 9. See more linked questions. Related Hot Network Questions. Question feed. Easy Normal Medium Hard Expert. Writing code in comment?
Please use ide. Load Comments. What's New. Most popular in Android.
0コメント