Pitch your project

Random text






Blogs

0    
By admin Category Uncategorized, Posted February 12th, 2016
AngularJS: Design patterns

There have always been a lot of discussions about what design pattern to use. There are several design patterns like: MVC, MPV an MVVM. When AngularJS was just released using the MVC model was more logic, but the framework improved over time. It came to a point where, for most, MVVM was the way to go. Because of this, it was unclear to developers anymore what design pattern was the way to go.
But the guys behind AngularJS ‘solved’ that in a clever way.

The design patterns

I mentioned above that there are several design patterns like: MVC, MVP or MVVM.

  • MVC stands for Model-View-Controller
  • MVP stands for Model-View-Presenter
  • MVVM stands for Model-View-ViewModel

I don’t want to make things to complicated, but there are discussions about how to use these patterns. I’m just gonna show an example of how it can be used.

Model-View-Controller

  • The model stores data and updates the view
  • The view shows data on the screen, users can interact with the view which will trigger something in the controller
  • The controller manipulates data in the model

Model-View-Presenter

  • The Model stores data, like the user’s name. It does nothing on it’s own.
  • The View shows data on the screen, users can interact with the view which will trigger something in the controller
  • The controller reacts on calls from the view, manipulates data in the model, and updates the view.
  • The key different with the MVC is that Model an View cannot communicate with each other

Model-View-ViewModel

  • The model sends notifications to the ViewModel
  • The View shows data on the screen, and sends notifications and data binding to the ViewModel on user interaction
  • The ViewModel sends notifications to the View, and updates the model.

What should you use for Angular?

Well, that’s what’s the discussion all about. Developers are spending hours and hours on discussing it.

The solution

The guys behind AngularJS posted this in response to all the discussions.

I’d rather see developers build kick-ass apps that are well-designed and follow separation of concerns, than see them waste time arguing about MV* nonsense. And for this reason, I hereby declare AngularJS to be MVW framework – Model-View-Whatever. Where Whatever stands for “whatever works for you”.

This solution made me laugh. It basically tells us that you should use it in a way you’re comfortable with. Just make sure you have a look at the AngularJS Guide

Posted by Nathan Taal

Leave a Reply

Your email address will not be published. Required fields are marked *