Tuesday, 4 November 2014

Introduction to AngularJS - Part 2

Model View Controller (MVC)

MVC application structure was introduced in the 1970s as part of Smalltalk. From its
start in Smalltalk, MVC became popular in nearly every desktop development envi‐
ronment where user interfaces were involved. Whether you were using C++, Java, or
Objective-C, there was some flavor of MVC available. Until recently, however, MVC
was all but foreign to web development.

The core idea behind MVC is that you have clear separation in your code between
managing its data (model), the application logic (controller), and presenting the data
to the user (view).

The view gets data from the model to display to the user. When a user interacts with the
application by clicking or typing, the controller responds by changing data in the model.
Finally, the model notifies the view that a change has occurred so that it can update what
it displays.

In Angular applications, the view is the Document Object Model (DOM), the controllers
are JavaScript classes, and the model data is stored in object properties.

We think MVC is neat for several reasons. First, it gives you a mental model for where
to put what, so you don’t have to invent it every time. Other folks collaborating on your
project will have an instant leg up on understanding what you’ve written, as they’ll know
you’re using MVC structure to organize your code. Perhaps most importantly, we’ll
claim that it delivers great benefits in making your app easier to extend, maintain, and
test.

No comments:

Post a Comment