What are the main advantages of the MVC pattern over the old-fashioned three-layer pattern

I am considering using the MVC template in my new project, and I clearly see the main advantage that you can put the data layer (model) a little closer to the presentation level (presentation), which will allow a slight increase in application speed. But besides the performance point of view, are there any other advantages of MVC compared to a view-logic-data-type template?

EDIT: For those who are interested, I just downloaded the sample PHP code that I created to test the use of MVC. I specifically omitted all security checks to make the code a little easier to read. Please do not criticize him too much, because I know that he can be much more refined and advanced, but nonetheless - it works !!! I will welcome questions and suggestions: Here is the link: http://www.sourcecodester.com/sites/default/files/download/techexpert/test_mvc.zip

+31
design-patterns model-view-controller n-tier 3-tier n-layer
Jan 01 2018-10-01T00:
source share
4 answers

Separating the issues that are cited as an advantage of MVC is also in fact the promotion of a three-layer / three-level system. There, too, the business logic is independent and can be used from different levels of presentation.

The main difference is that in a classic MVC model, it can have a reference back to a view. This means that when the data is updated, the model can return this data in several possible forms. The first example is a desktop application where data is visualized in several ways. It can be as simple as a table and graph. A table change (which is a change in one view) is first transferred through the controller to the model, which then returns it back to the chart (another view). Then the graph is updated.

Since desktop development is in decline, many programmers are only coming into contact with MVC in some kind of web-based option, for example. via JSF in Java EE.

In these cases, the model almost never refers to the view. This is due to the fact that basically the website is based on a request / response and after the request has been submitted, the server cannot send additional information. That is, an update transferred from the model to the client will be meaningless. With the reverse ajax / comet, this is changing, but many MVC web structures still do not fully utilize this.

Thus, in the case of web MVC, the typical “triangle” between M, V, and C is smaller, and the MVC variant is actually closer to the n-level model than the “true” MVC.

Also note that some MVC web structures have an intermediate piece of plumbing between M, V, and C called bean support (Java / JSF) or code (ASP.NET). In JSF, the controller is provided by the framework, and the view is often not attached directly to the model, but uses this bean support as an intermediary. The bean foundation is very thin and basically just pre-displays the data from the model in one direction and translates the messages specific to the model (for example, exceptions) to view specific messages (for example, some human-readable texts).

+42
Jan 01 '10 at 8:22
source share

Nearby

  • code reuse
  • separation of problems
  • less connection between layers

the already mentioned @bakoyaro and @arjan

I think MVC is better than three-tier in combination with the conditional configuration pattern. (i.e. "ruby on rails" or Microsoft "MVC for asp.net").

In my opinion, this combination leads to better and easier code maintenance .

Firstly, it makes learning the mvc-framework more difficult as you need to learn the conventions (a la-controllers are in the controllers folder and should be called xxxxxcontroller)

But after you have learned the conventions, it’s easier to save your own and external code.

+5
Jan 01 '10 at 9:03
source share

Forget about increasing application speed by switching to MVC. I found the biggest benefit for the convenience of code reuse. Once you upgrade to MVC, there is no dependency on the presentation of your data or the storage of actual data.

For example, you could write a servlet that loaded .jsp pages as a presentation layer one day, and the next day write a web service as another level of presentation for the existing model and controller. How wise, if you want or need to switch your DBMS. Since access to the model is completely separate from everything else, you just need to rewrite only the data access objects in order to return the data so that your controller can handle it.

By dividing the problems into 3 separate parts, you will also facilitate true unit testing. The presentation level can be tested without a model or controller and vice versa.

On the side of the note, I often felt that the abbreviation MVC was inaccurate. Whenever I see this, I think of it as View-> Controller-> Model . There will never be DAO code in the presentation layer, and there will never be presentation logic in the model. The controller is forced to act as an intermediate.

+2
Jan 01 '10 at 7:26
source share

If a three-tier segment separates a view from business and data access, MVC is a presentation-level template that further separates the model (data) from the View (screen) and controller (input).

It is not possible to select MVC for a 3-tier / three-layer. Use both of them.

0
Apr 26 '17 at 8:14
source share



All Articles