MVC development gets a new life in mobile apps

Microsoft, Java, and Ruby MVC frameworks are all adopting mobile-specific tools

Usually, technologists are quick to move on to the latest innovations and relegate older computing methods to the history books. But Model-View-Controller, or MVC, is a software development method that has withstood the test of time because, quite simply, it still works. Popular in Web application development, MVC is now finding a new life in mobile app development.

Despite being decades old, MVC is being applied to the latest trends in software development: Web and mobile applications. MVC arose out of the SmallTalk project in 1979 at the fabled Xerox PARC research facility. Adherents these days include major vendors such as Microsoft, as well as lesser-known companies such as Jupiter Consulting. MVC is used with the popular Ruby on Rails development framework and with the Spring Java framework.

MVC frameworks come in both client and server varieties. On the server side is Spring MVC, which is a module of the Spring Framework for Java development. Ruby on Rails also is server-focused MVC technology. On the client side is JavaScriptMVC, a development technology based on the jQuery JavaScript library. JavaScriptMVC 3 features a multibuild capability, which grabs shared scripts from different sites and provides optimal caching, says Jupiter Consulting CEO Justin Meyer, primary developer of JavaScriptMVC. Thus, he says, "JavaScriptMVC provides very solid functional testing for the browser." Other MVC frameworks include the Apple's Cocoa, Apache Foundation's Struts, Zend and the Symfony project for PHP, and the Catalyst project for Perl.

MVC's move into mobile apps
In Web development, "MVC gives you extreme control over the HTML and JavaScript," Hanselman says. Developers implement controllers that access server-side resources such as HTML for REST-based, server-side Web apps. Requests are routed the client to a Web server, and then to the correct controllers that process the requests. "It's the way to do it today," Donald says.

[ Microsoft last week released an upgrade to its ASP.Net MVC framework, with new capabilities such as dependency injection and "unobtrusive JavaScript." | Get the latest insigts on Java development with InfoWorld's JavaWorld Enterprise Java newsletter. ]

That same architecture makes sense for mobile apps, which is why mobile app development is becoming the new frontier for MVC. At Microsoft, "we recommend ASP.Net MVC for mobile application development," including for Apple's iOS and Microsoft's Windows Phone 7, says Scott Hanselman, community architect for Web platform and tools at Microsoft. (Over the next few months, he says Microsoft will offer formal recommendations and sample development code for the use of ASP.Net MVC in mobile application development.)

Likewise, the Spring Mobile project will extend Spring MVC to mobile applications; it is due around June and will enable detection of whether a client is a mobile device, says Keith Donald, a principal software engineer at SpringSource.

The benefits of MVC
In MVC, the model manages behavior and data in an application domain and responding to requests for state information. The view renders a model into a form suitable for interaction, typically as a user interface. The controller receives input and initiates a response by making calls on model objects. Input is taken from a user, and the controller instructs the model and viewport to perform actions.

MVC's separation of roles is its major benefit where it has long been used: Web applications. It's also a major benefit to mobile application development, where it's finding a new use. "MVC is a model for structuring your applications such that [there is] a separation of concerns," says Microsoft's Hanselman. "You don't want one part of your application to know too much about the other part." Additionally, "it helps lead to more maintainable code," says SpringSource's Donald.

MVC also brings structural benefits. "It's powerful to force structure on your code base, especially on large applications," says Jerod Santo, a contractor with Remote Software Development. "It helps developers and designers alike to think about pieces of the problem inside of a construct, which really keeps the code base clean and allows you to keep the business logic where it belongs, encapsulated by the models," Santo says. He has used Jupiter's JavaScriptMVC framework to convert the Grooveshark music-streaming application from Flash to HTML, JavaScript, and CSS.

"MVC is simply a great way of structuring applications," agrees Rails founder David Heinemeier Hansson.

Although MVC provides predetermined guidelines for developers to follow, it's critical for developers to understand how the Web works and how to use MVC's extensive controls, says Microsoft's Hanselman.

Remote Software's Santo advises proper maintenance of structure when using MVC. "One of the problems that people who are new to MVC usually have is that their controllers end up holding their business logic," he says. When business logic creeps into the controller, the controller can become unwieldy, so developers must push as much of the business logic as possible back into the model, where it can be more easily tested and encapsulated.

This story, "MVC development gets a new life in mobile apps," was originally published at InfoWorld.com. Follow the latest developments in programming at InfoWorld.com. For the latest developments in business technology news, follow InfoWorld.com on Twitter.

Copyright © 2011 IDG Communications, Inc.