Chapter 2. MVC and MVVM

The problem with software development is that we're always looking for the right way to do things. Each software shop will have their own set of guidelines that indicate how their developers should operate. This is the way that software works: we build a set of ideas that reflect our best thoughts on how things should be developed and the software community learns from these ideas and builds on them. They are formalized into patterns of working and these patterns are shared throughout the development community. In this chapter, we'll talk more about this concept, specifically:

  • The MVC pattern
  • The MVVM pattern
  • The way Ext JS uses both
  • The evolution of Ext JS from MVC to MVVM
  • The benefits of design patterns in the current version of Ext JS

Discussions about design patterns are often very dry. In this chapter, we'll use some practical examples to illustrate why they're so important and how they can help you kick-start your architecture efforts.

Diary of always

In the beginning, there was a giant mess. Well, maybe not quite, but in modern software development, we've got lots of design and architectural patterns that we can draw on to help us shape an application and ensure we're not reinventing the wheel. Each of these is the result of decades of their work, which is constantly reviewed and put into practice, and we all hope that the most elegant and useful work will bubble to the top. Along the way, we've seen clumsy patterns being overtaken by more elegant ones. Hopefully, our mess has become a little bit less tangled.

A key development in the way we build graphical interfaces was model-view-controller (MVC), which was invented at the near-legendary Xerox PARC in the 1970s by Norwegian computer scientist Trygve Reenskaug. It was first publicly incorporated in Smalltalk, a programming language developed by a cast of computer scientists including Alan Kay. It brought together a host of ideas, which influenced nearly all the object-oriented languages we use today. It was a pretty big deal and created by some pretty big guns.

Connelly Barnes, assistant professor of computer science at University of Virginia, gives us a great way of viewing MVC:

"The model is the data, the view is the window on the screen, and the controller is the glue between the two."

It was first in describing software constructs in terms of their responsibilities, for example, the View is responsible for presentation. In Chapter 1, Introduction, we talked about its importance in creating strong application architecture.

It can be difficult for us to look back on innovations (such as Smalltalk and MVC) and understand why they were so important. We could spend many pages reviewing what went before and why the advent of MVC has been described as a seminal insight. What really matters though is that it was a new way of looking at organizing graphical user interface-based software, a new paradigm in computing science that would prove to stand the test of time for the next thirty years:

Diary of always

Martin Fowler's bare-bones MVC

There are several differences between the MVC implementation that Ext JS uses (the one that Ruby on Rails brought to prominence) and the original implementation in Smalltalk. It has constantly been honed and tweaked since its inception, tailored for the various environments in which it has been used.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset