November 7th, 2007 · Posted by Nolan Wright ·

MVC is Dead

Model-View-Controller (MVC) was the exclusive design pattern for Web 1.0. These Web 1.0 MVC-based frameworks still dominate the world of web development, but that is about to change. Here’s my hypothesis:

MVC-based frameworks are simply unable by design to take advantage of the full power of Ajax and DHTML. Therefore, we must take a step back and a look at the problem of web development with a fresh perspective.

Note: going forward I will refer to “Web 1.0 MVC-based frameworks” as “Ralph” since the former is such a mouthful.

Ajax4Ralph

Many of the Ralphs have added support for Ajax (e.g., JBoss Seam via JSF/Ajax4JSF and Ruby on Rails). Let’s take a look at an actual Ajax request message from the JBoss Seam Hotel Booking Application:

Ajax-flavored Alphabet Soup

This is Ajax on Ralph – a clear illustration that Ralph is not designed to play nice with Ajax. To work with Ajax, Ralph must do unnatural and awkward things and the result is what you see above. There is another problem with Ajax and Ralph. Ralph forces an almost airtight coupling between the user interface and the server, whereas Ajax enables a near-100% decoupling of the user interface and the server. Viewed in this light, you can see that Ralph and Ajax are at odds, so it should not be surprising that when combined the result is a train wreck.

DHTML4Ralph

DHTML enables you to create highly dynamic user interfaces. You can hide or show an element, change CSS properties on the fly, drag-and-drop elements, and much more. How does Ralph help you with DHTML? To date, Ralph gives you two ways to incorporate DHTML:

  • You can handwrite Javascript
  • You can integrate with a third-party DHTML-toolkit like Dojo.

Both solutions can help you build dynamic applications, but neither is ideal or integrated. Handwriting Javascript is a nightmare. I know because I’ve done it. Over a year ago, I wrote a nice login/signup page; it was highly dynamic, and it looked and performed quite well. The problem was it required 1400 lines of code - 1000 of which were Javascript. It was clear that this approach was deeply flawed and had absolutely no future.

Next, I tried using toolkits like Dojo. This approach required me to write less Javascript, but integration was not straightforward. These toolkits are also hard to customize and they still require you to write a fair amount of Javascript. The biggest problem is that they are not integrated; they are “bolt-ons”.

At best, Ralph has “bolt-on” support for both Ajax and DHTML. You can certainly create next-generation applications using Ralph, but you can also eat nails; neither is a fruitful experience. The problem is simple: Ralph was designed in a time before Ajax and DHTML. In his defense, Ralph has tried hard to support these technologies, but the result is awkward and difficult to use. Good engineers know instinctively when it’s time to take a step back from a problem and look at it with a fresh perspective. Now is that time.

With that in mind, it’s time for my next hypothesis:

Ajax and DHTML are highly complementary technologies - when combined they enable the creation of web applications that can surpass the capabilities of today’s desktop applications. As a result, a next-generation Web SDK is needed - one that seamlessly integrates Ajax and DHTML.

Introducing the SOUI (like the pig call: soo-wee!)

SOUI stands for Service-Oriented User Interface. The foundation of a SOUI is a message-based architecture - meaning everything in the user interface is controlled via lightweight messages. Think about being able to control both the look of the user interface and the interaction with services using a single messaging paradigm. With one message, you can hide 3 HTML elements, show another, and send a service request – pretty cool. The SOUI also provides an abstraction layer that seamlessly integrates DHTML and Ajax - giving developers the benefits of Ajax and DHTML without having to write any Javascript. The result is a powerful, streamlined, and highly flexible way of building dynamic user interfaces, but enough talk, let’s look at some code:

1
2
3
4
5
<!-- SHOW AN INDICATOR ON SAVE, HIDE ON RESPONSE -->
<img src="http://www.example.com/indicator.gif" 
 on="r:user.save.request or r:user.save.response then hide"/>
<!-- SEND A REMOTE USER SAVE REQUEST -->
<input on="click then r:user.save.request" type="button" />

In the example above, clicking the button generates a message, which results in two actions: an Ajax request to a service and a DHTML action that shows a spinning progress image. When the Ajax response is returned, the image is hidden using another DHTML action. That’s SOO-WEE! – simple, yet powerful.

The message-driven nature of a SOUI also provides some other significant benefits:

  • You can create client-only prototypes that are fully functional since they can use local mock message handlers. The SOUI does not know the difference between using a mock message handler and using a service.
  • These prototypes are 100% re-usable – just swap out the mock message handlers for the actual services without changing any SOUI code.
  • You create a simple message-based contract between the SOUI and its services. The result is a near-complete decoupling of the client and server; they are linked only by a lightweight message contract.
  • You can change your server programming language without changing a single line of SOUI code.

SOA for Web Applications

A SOUI-based client opens the door for some interesting things on the server. Since SOUIs talk to services using lightweight messages, services can now be written in any programming language. In other words, a SOUI is programming language-agnostic. It can talk to services in Java, Ruby, PHP, .NET or any other programming language you can dream up. It can also simultaneously access services in different programming languages. These powerful capabilities are enabled by the lightweight message contract between the SOUI and the service. The only knowledge shared between the SOUI and the service is this contract. Let’s take a look at one of these messages. The message below is how a SOUI would request data from a service providing the same capabilities as the JBoss’ Seam Hotel Booking example provided earlier:

1
2
3
4
5
  <request version="1.0" idle="403">
    <message requestid="2" type="hotel.search.request" datatype="JSON">
	<![CDATA[{"searchKey":"Atl"}]]>
    </message>
  </request>

Within this message lies the Message Request Contract. This contract has two parts: the message type and the message data. The message type in this case is hotel.search.request. The message data for this contract is searchKey. So we have a service that responds to all requests for hotel.search.request and it requires an value for searchKey to do its job – simple, yet powerful. Let me hear you squeal – SOO-WEE!

This lightweight message contract should also greatly simplify service development. There is no longer a need for the heavyweight infrastructure required by Ralph. In Java, I should now be able to create a plain Java object (POJO) and add a single annotation that instantly makes it a service that can be consumed by a SOUI. Here’s an example Java service:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class HotelService
{
   @InjectBean
   HotelDAO hotelDAO;
 
   @Service(request=”hotel.search.request,response=”hotel.search.response)
   public hotelSearchRequest(Message request, Message response)
   {
	// get request data
	String searchKey = request.getData().getString(“searchKey”);
	// perform search
	List<hotel> hotels = hotelDAO.findByName(searchKey);
	// send response
	response.getData().put(“hotels”,hotels);
    }
}

As you can see, the SOUI unleashes the full power of an SOA-based architecture for web applications. Web service developers can now focus solely on developing a set of reusable data services in the programming language of their choice, and they no longer have to co-mingle service logic with presentation code. And user interface designers are now free to rapidly create highly dynamic user interfaces with less code and without the constraints of Ralph’s forced-coupling of client and server technologies.

Now What?

My business partner Jeff Haynie and I went through this thinking over a year ago. We were frustrated by the state of web development platforms. Our conclusion was that it was time to take a step back and design a solution that would unleash the full power of Ajax and DHTML and solve the coupling problem created by Ralph. The result is Appcelerator. We’ve been building applications with Appcelerator for over a year and the result has been phenomenal. In short we’ve been able to build highly dynamic applications with significantly less code in a fraction of the time - hence our tagline: More App Less Code.

This is just the beginning of the what’s to come. The implications of an Applcelerator-type platform do not stop with development. The effects are far-reaching, incredibly exciting and will change how people build, deploy and manage web-based applications and services.

Popularity: 23% [?]

Tags: Opinion · SOUI

9 Responses to “MVC is Dead”

  1. Mike Says:

    I hope you’re not serious about that first piece of code, because I don’t think anyone is interested in proprietary attributes, especially if they contain programming code, nor is anyone interested in controlling visibility with anything but CSS.

    In fact, I don’t see how this SOUI is anything but JavaScript requesting data in the form of XML or JSON and chaning the UI when the request is done. It’s just another acronym so it sounds new. In fact, using ASP.NET you can now decorate a webservices with a [ScriptService] attribute, and you’re halfway there. All you need is something like the ExtJS framework to interpret the response and build your UI and you have a so called SOUI…

  2. Roger Says:

    Would be interested in hearing what you think about Flex. It appears that Flex does what you are talking about (i.e: SOUI) albeit using a different syntax.

  3. Nolan Wright Says:

    Mike,

    There is nothing wrong with the approach you described except that it’s not integrated, so you will have to write some amount of integration code.

    At Appcelerator, we offer a fully integrated platform. This enables us to focus on building applications instead of writing integration code.

    As for your “proprietary attributes” and “CSS” comments, you might be right. I think what people are interested in is being able to quickly and easily build great applications. If a proprietary attribute or expression language help to significantly reduce the time and cost to do the same job - I think people will be interested.

    We’ve been building applications for customers (and for ourselves) with Appcelerator for over a year, and I can tell you from personal experience that it drastically reduces development time.

    Thanks for the comments. Different perspectives are always appreciated.

  4. Nolan Wright Says:

    Roger,

    I think Flex is similar. It promotes a client/server architecture and it does provide some of the same capabilities as Appcelerator. Our approach is different in two major ways:

    1) We provide a fully integrated services platform that allows you to write services in Ruby, PHP, and Java (.NET and Python will be coming soon).

    2) We allow you to use standard HTML and CSS. We have a single attribute, “on”, that can be added to any element to either send or receive messages (local or remote) or perform one or more DHTML-based actions like hide or show or changing any CSS property.

    We did a comparison of Appcelerator and Flex recently (as well as OpenLaszlo and Google Web Toolkit). The results were interesting. We haven’t posted the findings on our site yet, but I would be happy to share them with you - just shoot me an email at: nwright@appcelerator.com if you’re interested.

    Thanks

  5. Steve Conover Says:

    1.MVC

    Any problem that involves a user interface (both display and interaction) and data has the potential to have MVC applied to it - this will probably be true forever.

    We know this because MVC was popularized in a heavy-client era. We went back to the server for a while, now we’re all back on the client.

    …and just last month I was involved in writing a nice client-heavy js/json/ajax/rails app that had full-on MVC separation in the js, we loved it. Long live MVC.

    “Handwriting Javascript is a nightmare. I know because I’ve done it. Over a year ago, I wrote a nice login/signup page; it was highly dynamic, and it looked and performed quite well. The problem was it required 1400 lines of code - 1000 of which were Javascript. It was clear that this approach was deeply flawed and had absolutely no future.”

    I hope you reconsider this, radically. I think that’s exactly the wrong takeaway. Prototype, Mootools, JsUnit, Intellij Idea, etc etc make this a pretty modern programming environment, and now that the OO community is taking an interest in js, most of those nice OO abstractions and utils you’re used to are out there. I feel very productive in js - not like ruby, but not all that far away either.

    I don’t know what you were up to on that signup/login page but that number of lines of code seems very high. I’ve made similar pages and not come anywhere close to that.

  6. Nolan Wright Says:

    Steve,

    I actually agree with your MVC comment. Our client architecture is very much like the MVC separation you mentioned in your “client-heavy” example. My post was really geared towards one of things you pointed out: “now we’re all back on the client”.

    As for your Javascript comment, we are 100% committed to helping people build rich Internet applications faster. To the degree that a particular JS tool or framework helps with that, we will look for ways to incorporate it (or something equivalent to it) into Appcelerator.

    Thanks for your comments.

  7. Tejus’s Blog » Using Site Specific Browsers to Enhance the Web Experience Says:

    […] is where the SOUI (service oriented user interface) paradigm of Appcelerator really shines. To refresh the groups […]

  8. Using Site Specific Browsers to Enhance the Web Experience Says:

    […] is where the SOUI (service oriented user interface) paradigm of Appcelerator really shines. To refresh the groups […]

  9. Rafael Says:

    The MVC pattern is not a panacea, but solves a lot of problems and can be used to produce stable and reliable applications. I guess most of the your interface problems can be solved with little CSS and JavaScript (I wonder what your 1000 lines were all about, since something like a drag-n-drop can be done from scratch in about 60 lines of code, and yes, from scratch, without prototype). Saying MVC is dead sounds very radical, and your arguments did not helped you at all.

Leave a Reply