Sunday, January 30, 2011

MVC for User Interface layer


Benefits : The biggest benefit has to be decoupling of presentation; MVC allows presentation (UX or UI) to work in isolation and establishes boundaries. Specialized developers can work on UI without having to worrying about how domain entities are structured and vice-versa.

There are of course lot of other benefits which come with ownership of UI artifacts by UI developers.

a. Device dependent presentation layer stays out of your code base.
b. Accelerates development and changes to presentation layer.
c. Facilitates automation testing of everything beneath presentation. UI based automated tests are harder to write and expensive to maintain; MVC would allow to write tests on view models, controllers and domain layer; giving you bigger bang of your buck.
d. Accelerates development of business logic by freeing developers from UI concerns.

Typical Microsoft MVC set up doesn't take much; just start by creating a MVC application in Visual studio.

1. Set up views - Html, javascript/jquery and style sheet. Utilizes view model to interact with domain. Views setup requires at least four folders in web application folder; set up Views, View models, styles and scripts folders.

View models concerns - Typical view model exposes properties required by view; houses logic for conversion of domain entities to view model. Look up auto mappers.

2. Set up Controllers - Controller should have there own folder. Controllers and view models do not need live in web application assembly; I would leave there unless there is compelling reason not to. This is where MVC ends.

Controller concerns - Interact with domain; pass on data back and forth between domain and view. Code layout of controller is typical facade pattern if anything. Controller commands domain to process view interactions and view model to process domain entities to formulate a view.

NOTE: I find its important to come up with clean folder organization; I have seen following same structure with in each artifact folder works very well.

No comments:

Post a Comment