Dataworks Blog

    WHY ASP.NET MVC ?

  • Why ASP.net MVC ?

    In the late nineties developers on a Microsoft stack would have been using Active Server Pages (ASP) for server side scripting and would have had to have a reasonable understanding of web development i.e. the stateless nature of the web and use of the HTTP protocol in general.  At that time, Microsoft had a large network of Visual Basic developers developing windows based software.  ASP.net, first released in 2002, provided a path for these developers to get into the rapidly growing space of web development with a reduced learning curve.  

    This reduced learning curve was achieved by abstracting the stateless nature of the web using mechanisms such as viewstate and postback.   ASP.net allowed controls to be dragged to the page, code behind allowed events to be added to these controls, encouraging an event driven GUI approach to web development.  This provided a development environment familiar to those migrating from Windows desktop development but had some drawbacks.  This level of abstraction meant that developers where removed from the stateless nature of the web.  Code behind classes, introduced to reduce the amount of code mixed in with HTML on the web pages, often became tangled, with business logic being mixed in with UI related code.  

    In parallel to ASP.net moving through several versions, web development outside the Microsoft stack was going through some major changes.  Some major leaps forward came with the adoption of Javascript libraries on the client and MVC frameworks on the server side. Client side Javascript libraries such as Jquery, Prototype etc. greatly simplified client side scripting.  Server side frameworks such as Ruby on Rails allowed for quicker development of web based applications while being true to the stateless nature of the web.  These advances encouraged the use of RESTfull URLs and facilitated Test Driven Development (TDD).  TDD was becoming increasingly important to web application development, particularly where Agile methodologies were being adopted.

    With the release of ASP.net MVC Microsoft embraced these advances in web development and offered developers on the Microsoft stack an alternative to ASP.net web forms.  ASP.net MVC now on version 3 with version 4 in beta offers the following advantages. 

     

    Separation of concerns

    Core to the ASP.net MVC framework is the design pattern behind the acronym in its name, Model, View Controller.  Separation of concerns is fundamental to this pattern, which can be summarised as follows

    Model: The model contains the business logic of an application, retrieves data and enforces validation rules

    View: The view contains the user interface of an application

    Controller: The controller classes manage the control flow.  These interact with the model and return appropriate views.

    Software always changes. The separation of concerns provided by this pattern allows for greater flexibility, thus making change less painful. For example, a view can be changed independently of the controller and models.  This also allows different developers to work on different parts of the application in parallel.

     

    HTML and Javascript

    ASP.net provided a drag and drop event driven GUI builder postback and viewstate, which aided Rapid Application Development (RAD), had a cost in terms of control over the HTML mark-up.  ASP.net MVC allows full control over your HTML mark-up.  This allows for the adoption of HTML5, cleaner CSS and enables integration with Javascript libraries such as JQuery, all essential for modern Rich Internet Application (RIA) development.

     

    URLs

    ASP.net MVC encourages the use of RESTfull URLs.  These URLs are human readable, SEO-friendly and discoverable, for example

    http://mysite/products.aspx?caregory=shoes&product=flipflop

    vs

    http://mysite/shoes/flipflop 

     

    TDD

    One of the main advantages of SOC mentioned earlier is that it facilitates Test Driven Development (TDD).  With the adoption of Agile methodologies TDD has become an essential part of web development.  Tightly coupled code is difficult to test.  ASP.net MVC encourages loosely coupled code which enables TDD.

     

    Web forms or MVC?

    Of course web forms have their place; they may provide a better fit for developers with less experience of web development as it’s more like windows forms development; they are arguably better for Rapid Application Development (RAD), though this has a cost when it comes time to change and maintain.

    Microsoft fully supports both approaches and plan to do so for the foreseeable future so either approach is valid.  At Dataworks we like what we’ve seen with ASP.net MVC and most of our new web application development is adopting this approach.

     

     

  • Back to Blogs