Peculiar Choices Made in the Microsoft Implementation of Model View Controller or MVC
by Jeffrey Sward
 
Definition of Model View Controller (MVC)

Model-View-Controller (MVC) is a design pattern for computer user interfaces that divides an application into three areas of responsibility:

  • Model: the domain objects or data structures that represent the application's state.
  • View, which observes the state and generates output to the users.
  • Controller, which translates user input into operations on the model.

The model captures the domain logic of the application with a strong separation from the way that the user requests and sees the results. In theory, the latter are managed by the view and controller together, under the constraint that input usually does not trigger output directly. Instead, the model triggers output when it detects that an action has caused a significant change in its state

Martin Fowler said that at "the heart" of MVC is making a clear division between domain objects that model our perception of the real world, and presentation objects that are the GUI elements we see on the screen. Domain objects should be completely self contained and work without reference to the presentation, they should also be able to support multiple presentations, possibly simultaneously.

Full separation of domain and presentation can be better accomplished by completely separate poco c# objects organized into namespaces such as business logic, display, data access, utility, etc. Separation of concerns in to separate object spaces can be accomplished equally well regardless of whether MVC or the ASP page model is being used.

Peculiar Choices Made in the Microsoft Implementation of MVC

MVC has existed in various Java implementations for approximately ten years before MVC was discovered by Microsoft. Java MVC implementations generally involve additional class libraries which work within the JSP page model.

Rather than implementing Microsoft MVC within the ASP page model, Microsoft made the peculiar decision to invent a completely new page delivery mechanism for Microsoft MVC, completely unrelated to the ASP page model.

Disadvantages of the Microsoft MVC Implementation

MVC is a design pattern for segmentation of code into functional groups. Implemented other languages mvc is usually an object API set used within the standard page model. The mvc concept should not be implemented as a new independent development environment. There is no technical or business reason for a completely separate mvc environment.

The Microsoft mvc implementation has instead created a completely new mvc programming environment. The separate mvc environment creates an unnecessary burden to learn the environment. The forced isolation of the layers hides interaction, making behavior much more difficult to understand. If the object API method was used, it could interoperate with the existing page model, building on the existing knowledge base rather than ignoring the existing knowledge base. Another peculiar deficiency is that the Microsoft mvc environment does not even rigorously following the mvc design pattern.

The Microsoft MVC environment introduces new levels of indirection and thusly increases the complexity of the solution. It also increases the event-driven nature of the user-interface code, which can become more difficult to debug. The complexity is high to develop applications using this pattern.

If different groups work independently on the layers, coordination may become particularly difficult. The isolated development process by UI authors, business logic authors and controller authors may lead to development delays in their respective modules. For example, developers cannot completely ignore the view of the model even if they are decoupled. If the model undergoes frequent changes, the views could be flooded with update requests. As a result, the view may fall behind with too many update requests.

Microsoft MVC encourages URL rewriting in code. Hard coding urls in code is a bad practice. There is no generic MVC requirement for hard-code controlled page navigation.

Microsoft MVC encourages dynamic HTML generation in c# code.  MVC should be about separation of concerns rather than generation of the presentation layer in the code layer.  

Extravagant claims are often made for each new technology gimmick, and Microsoft MVC is a prime example. The usual assortment of unsubstantiated claims have occurred, such as "completely test driven," "full separation of display and logic," "complete decoupling of developer tasks from designer tasks," etc. It is entertaining to note that each of the same claims were made during the introduction of Microsoft ASP.Net.

Survival Strategy for Forced Marches to Microsoft MVC

Neither the Microsoft ASP page model nor Microsoft MVC guarantees well structured and maintainable applications. Well structured and maintainable applications instead depend on good architecture, good design, and good coding discipline.

As there may be some forced march to Microsoft MVC in some environment, the following survival strategy is suggested:

 
Item Strategy for Asp .Net Strategy for Microsoft MVC
Visual Elements aspx and ascx cshtml
Business Logic Completely separate set of poco c# business logic objects unrelated to running the visual application Completely separate set of poco c# business logic objects unrelated to running the visual application
User Driven Navigation Relative hyperlinks in the aspx layer Relative hyperlinks in the cshtml layer
Code controlled URL redirection Bad practice. Avoid. Bad practice. Avoid.
Response to user events Code behind page calls appropriate methods in completely separate poco c# utility objects Controller calls appropriate methods in completely separate poco c# utility objects
Connection strings web.config web.config
Access data Code behind page or poco c# business logic objects call appropriate methods in completely separate c# data access objects Base model stubs or poco c# business logic objects call appropriate methods in completely separate c# data access objects
Render data Bind in aspx layer Bind in cshtml layer
     
 
Links

http://msdn.microsoft.com/en-us/magazine/dd942833.aspx

http://msdn.microsoft.com/en-us/magazine/cc337884.aspx

http://www.codeproject.com/Articles/187556/Comparison-of-MVC-implementation-between-J2EE-Stru

http://eric.polerecky.com/a-completely-biased-comparison-of-aspnet-mvc-and-webforms/

http://codebetter.com/karlseguin/2010/03/11/webforms-vs-mvc-again/

 
 
 

All written content of this web site is solely the editorial opinion of Jeffrey Sward. All images, graphics, and written content of this web site, including the html files, are creative products covered by copyright law. All content copyright Jeffrey Sward 1975-2019. All rights reserved. No portion of this web site or its constituent elements may be reproduced in any form, by any means, without prior written permission. So there.