Monday, March 30, 2009

Director Scene View (DSV)

What is DSV?
DSV is a UI design pattern that borrows from other popular patterns such as:

  • Model-View-Controller (MVC)
  • Model-View-Presenter (MVP)
  • Model-View-ViewModel (MVVM)
When developing enterprise .NET applications it is important to consider:
  • Testability - The ability to test the functionality of isolated units in your application.
  • Extensibility - The applications ability to be extended by adding new features, functionality, and modules.
  • Maintainability - How easily your application is to maintain through debugging.
The goal of DSV is to address these concerns in a clean cut, well defined, easy to understand manner.
First I'll explain the responsibility and purpose for each element of DSV then we'll get into some code samples.
  • Director - Your application's UI logic will be composed from many of these. Each director will be responsible for creating the View, creating the Scene, then setting the Scene property on the View. It will also listen for event's on the View(s) it creates to handle user interaction.
  • Scene - The scene contains all the data (exposed through properties) that is required to support the View. The view will bind to the Scene using data binding.
  • View - The View is your actual user interface (usually a user control). It has a property to set the Scene to which it binds it's controls to. The View also raises events to notify the Director of user interaction.

Now some code, in this example we will be working with an Employee entity. In this example I will be using Microsoft patterns & practices Composite Client Application Guidance.

I wanted to put the code directly in the post, but I’m having a hard time doing that with blogger, so here are links instead:

EmployeeDetailsDirector

EmployeeDetailsScene

EmployeeDetailsView

The example of the View is using WinForms, I’m working on a more complex example using WPF.

As you can see, using DSV we can achieve clean separation between the UI, the UI logic, and your entities(data) . This makes our application easier to debug as well as enables us to test our UI logic by simply creating a mock view and writing unit tests against our presenters. The Composite Client Application Guidance compliments DSV very well giving us a high level of extensibility through view injection, composite events, and modules.