Silverlight Best Practices: The MVVM Pattern
The early messaging around Silverlight focused around rich multimedia experiences and the ability to play movies within a browser. Many consumers felt that Silverlight was simply another video player plug-in designed to compete with the ubiquitous Flash player. It wasn’t until 2009 and version 3.0 that Silverlight applications became prevalent in the enterprise. The ability to write an application once and have it run with exactly the same functionality and user interface on multiple platforms and browsers, along with the ability to operate in off-line mode when disconnected from the Internet, made it the perfect candidate for business applications.
Silverlight has powered applications ranging from server monitoring systems for large redundant data centers to rich interactive online schedules for cable providers. Through SharePoint integration, Silverlight has provided rich interactive interfaces for financial risk management applications. It has been used in military applications, educational software, and for medical field technology. Silverlight has established itself as a powerful framework for building line-of-business applications.
This series will focus on best practices for using Silverlight to write commercial applications. Enterprise applications have unique requirements that can be addressed using various patterns and solutions that are available within the Silverlight framework. This first article will examine the common MVVM pattern. MVVM is the abbreviation for model-view-view model. This pattern is a variation of the MVC pattern, or model-view-controller. It is popular in line-of-business Silverlight applications because of how well it works with XAML and data-binding.
Design Pattern Versus Framework
MVVM is a design pattern. A design pattern is a general solution for a software problem that can be reused across different projects. It is a concept and not a specific code base. It is important to understand the difference between the pattern and the framework. MVVM as a pattern does not dictate how the pattern is implemented nor does it provide specific code, but instead provides the general solution to separate concerns in applications that use data-binding.
A framework, on the other hand, is a collection of code that provides specific functionality. Frameworks often provide libraries that can be accessed via a well-defined Application Programming Interface (API). Frameworks are often flexible and extensible, but do implement core functionality that is intended to be reused rather than modified. There are several frameworks available for Silverlight that implement the MVVM pattern. These will be discussed after the pattern itself has been defined.