Alternatives to MVC for web applications

Asked

Viewed 3,943 times

17

Context (TL; DR)

When we talk about architectural design patterns, we usually talk about MVC. For the web, we usually use something like the following image:

Web MVC

So much so that much of the frameworks we have, like Zend, Symfony, Rails, among others, usually use implementations of this standard, and/or its variations/interpretations. When I studied Systems Projects, this was also the standard spoken most of the time. The projects were done in MVC, the tests, in MVC, and what we talked about in the courtyards, was MVC.

My case

One day, talking to some colleagues, I decided to make a framework (madness, no?!) to support the company’s web applications (in PHP), with support for team standards, legacy code, etc. Of course, with so much influence, I started writing the same blessed in MVC, and is already in its second version stable.

However, today came to me a doubt, if I really made a good choice when choosing MVC, and I did not consider the existence of other standards, nor did I question such "absolutism" of it.

Questions

When it comes to architectural standards, what alternatives do we have in literature, use of the MVC, and which advantages and disadvantages in relation to other standards, in this type of application? What examples of renowned non-MCV frameworks can we take?


Important remark: My goal with this question is not just to get a list of patterns, if it were for that, a search in Google would suffice :) I’m much more interested in knowing its advantages and disadvantages for Web applications, so I can make a decision literature-based, case studies, and not in the personal opinions of each.

  • Xi! Only MVC architectures already exist several varied variations. The "original" MVC designed for desktop applications in Smalltalk used several small Mvcs for a screen -- similar to what some frontend frameworks have been doing. Humanity still does not know how to answer this question happily in the context of the Web, you’re in for Trouble, little man! =)

  • A website with only static pages takes the M from the MVC. It may look like something Jedi, but for simple websites that perform a single function, a database often doesn’t even make sense. As a website that calculates, translates or informs something.

  • Can nothing really exist but the MVC and its collection of children or adaptations?!

  • When talking about the subject in a stricter context of "web applications", templates (ex. XSLT, Smarty) and client-frameworks (eg. Bootstrap) are bugs that catch... giving the final face of their architecture.

3 answers

13

MVC as Pattern?

In fact I classify MVC more as layer splitting than a purely said Pattern.

The MVC came to distribute responsibility between the layers of the project.

It is very easy to add business rule amid your VIEW layer, as this reduces cohesion and creates a high coupling of your classes. When we have the project separated in layers we can have a better use of code, greater cohesion, smaller coupling and so on.

A MVC-based framework is good because it makes it easier to use. A developer will know that just fiddle around to create a system entry and then create a location to receive and handle the request.

What to use then?

There are several Patterns that can be used to make your framework really usable. I could cite some as:

  • Front Controller
  • Intercepting Filter
  • View Helper
  • Dispatcher to View
  • Service to Worker

Note that these patterns can be used in an MVC project. The correct thing to do would be to understand how these standards work, even if you are a developer of another language, and apply to your project.

Completion

MVC is a standard that works well, helps maintain healthy and practical code.

Of course, even with the best framework in the world in the hands of a bad developer it won’t do any good.

What matters is to create a framework that is well done and that can help in any way possible.

  • I already have Front Controller, View Helper, and Dispatcher. I will study the need to include more standards in version 3.

  • @Calebeoliveira Framework maintenance tends to get very difficult over time. I suggest to avoid adding filters that are possible to solve with a library.

12


There are already many variations of MVC, Symfony, Cakephp, Codeigniter themselves say they use MVC, but it is not the pure standard, they say this so as not to scare the community with the thousands of layers they have.

There are several layers that help the three main layers, such as a service layer between the controller and the model, object transfer layer known as DTO, repository, between the database and the model and so on.

Choosing a framework to develop an application is the main decision a developer can make. 'Cause it will either attach the system to the adopted model for the rest of its life, or be re-coded.

I recommend that you read on the blog of the creator of PHP, Rasmus Lerdorf, to criticizes what he does about frameworks fashion. He criticizes the creation of so many layers, and it would be possible the same thing in an organized way and with much more performance.

Below I mention other layers that you can study if you are interested.

Service

The service layer is between the controller and the models. In this layer will be the whole rule of business of an action, independent of a user interface. By using a service layer it is possible to isolate your business rules that involve more than data manipulation. Leaving the controller to handle the processing views need.

The main advantage would be the possibility to rewrite your entire user interaction layer, or even create several, without having to worry about the business rules.

A good example is the possibility of creating a web application and a mobile application communicating directly with the service layer, where each one would have its layers of views and controllers.

If you used pure MVC, a lot of code would have to be rewritten in the controllers, because the rules that View imposes on the controller may require different treatments or even returns.

DTO

DTO is actually a standard that helps you standardize communication data between layers, enabling in many cases the use of dependency injection.

Using DTO is an excellent way to program Apis or deal with webservices.

Repository

In the original concept of MVC, the model is responsible for the entire business rule of using the system’s information, so all manipulation and communication with the database is mixed in there. The repository layer appeared to separate communication from manipulation, leaving more readable and organized all the code of the model, besides allowing much reuse of code.

MVP

In short, it is a direct model between a View and Presenter layer. Think of an application where the view makes Javascript requests, and Javascript itself performs the entire business rule. It is a model that has been growing a lot due to the scalability that makes possible.

See the comparison between Frameworks in this model,

Learn the difference between MVC and MVP.

--

Although the above mentioned layers seem to be only patterns, they are present as true layers, even in the frameworks we use. An example is Doctrine that has the repository layer and Symfony create its template layers where all the code makes use of the repository layer to communicate with the database.

It is worth studying a little about each one to visualize well how the layers are separated.

Some other suggestions Hexagonal Architecture I don’t have much knowledge to say.

  • Currently, my framework has only three layers, it is very light and robust for what is demanded. Just like the image I posted in the question.

  • Your comment There are already many variations of MVC, Symfony, Cakephp, Codeigniter themselves claim to use MVC, but it is not the pure standard, practically answered part of my doubt (in another question), I really believe what you said. Thank you very much :)

7

Boas Calebe, MVC is a great choice of Pattern for a web application, although it was created for desktop applications, it is a perfect choice for the web as it separates the various layers/technology existing in a web application, M -> ORM/SQL, V -> HTML/CSS/JS, C -> C#/PHP, etc...

MVC also offers classic three-layer separation, data, logic, presentation.

More what I like is the principle that it offers and that I try to use in all my projects, MVC or not, DRY (Don’t Repeat Yourself).

There are already some derivations of MVC, such as HMVC, MVVM, MVP, etc ... where each one adapts well to the problem to be solved.

I particularly like to use HMVC, because it is MVC separated into several modules/Triads, and I’m even making a HMVC framework :) "(crazy, no !? )", which by the way is super flexible and fast :)

http://pedrosimoes79.github.io/silverbullet/

PS: Attention is just a preference of mine.

HMVC allows for example to have a MVC Triade to handle several layout blocks, such as header and footer, in the views or controller of the application, I can simply call the 'layout/header' controller and then at the end the 'layout/footer', without ever needing to dirty the controller called, who says layout, says other things.

This is a HMVC diagram, although in my framework you can also call a MVC from a view, as if it were a template:

HMVC Pattern

and videos explaining HMVC using Codeigniter https://www.youtube.com/watch?v=8fy8E_C5_qQ

Browser other questions tagged

You are not signed in. Login or sign up in order to post.