Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Downloads | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
World Class ASP.NET Hosting - 3 Month Free Hosting, Click Here!
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » ASP.NET MVC & JQuery » Introducing MVC: A Model View Controller Framework for .NET Platform

Introducing MVC: A Model View Controller Framework for .NET Platform

This article explains the MVC pattern essentials and then walks through the key features of the MVC Framework which helps building true MVC based solutions.

Technologies: .NET 3.0 and 3.5,Visual C# .NET
Total downloads :
Total page views :  10396
Rating :
 5/5
This article has been rated :  1 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
Become a Sponsor


Related EbooksTop Videos


Introduction

This article gives an overview of MVC# -A Model-View-Presenter framework for .NET platform. It firstly explains the MVP pattern essentials and then walks through the key features of the MVC# framework which help building true MVP-based solutions.

What is Model-View-Presenter?

3-tier architecture

One of the most fundamental approaches in software engineering is the Layered architecture. It implies dividing a system into several interacting layers with certain limitations imposed on how layers may interact.s Layered architecture finds its application in various systems for example net protocols (TCP/IP layers), operating systems (three layers: core, drivers, applications) and others.

A particular case of layered architecture is the 3-tier architecture with its variations: Model-View-Controller and Model-View-Presenter. Before considering MVP (and MVC) let us discuss the general 3-tier architecture and its difference to the conventional programming style.

A straightforward (and widely used) approach in designing applications is the 2-tier architecture. According to it an application consists of a presentation layer and a domain layer. Domain layer classes represent the problem domain entities (e.g. customer, order) and are usually bound to some database access facilities. Presentation classes in 2-tier architecture have the following responsibilities:

  • receive user input
  • make necessary calls to the domain tier
  • decide what to show next to the user
  • display output

These responsibilities are rather vast and, as a system grows, may result in a bloated presentation layer. Moreover they logically can be divided into two groups: actually presentation logic (code for perceiving input and displaying output) and application logic (communication with the domain tier and application flow decisions). These responsibilities require different programming skills and should better be not mixed in a single module/class. A quite natural solution is to split this too broad presentation layer into two: presentation and application logic:

Untitled-1.gif

3-tier architecture is rather abstract. While it declares an existence of three layers, it says nothing about classes in these layers and their interaction. A much more precise form have two 3-tier architecture variations: Model-View-Controller and Model-View-Presenter. Let us proceed to their discussion.

MVC and MVP patterns

According to both MVC and MVP the presentation layer consists of view objects, and application logic consists of controller objects (we will use "controller" name instead of "presenter" in MVP). For each view object a corresponding controller exists and vice versa. And although MVC and MVP are based on a common 3-tier principle: views process only presentation needs and controllers handle application logic, these patterns have two major differences:

  1. In MVC controllers receive and process user input, but in MVP views receive user input and then merely delegate processing to the corresponding controllers. That is why MVP pattern better fits modern UI environments (Windows/Web forms) where view classes themselves handle user gestures.
  2. In MVC controllers affect their views by changing the intermediate presentation model, which the views are subscribed to (by observer pattern). This makes views pure observers without direct access to them. MVP on the other hand violates this "pure observer" rule by providing a direct link from a controller to its view. This makes MVP more handy as compared to MVC.

Untitled-2.gif

The said differences make the MVP pattern more attractive than MVC from the developer's point of view. And indeed MVP was designed to be an evolution of MVC and to improve the latter. That is why we often refer to MVP as "sharp MVC" and therefore the name our MVP framework is MVC#.

Why using MVC#?

Now that we are convinced in the usefulness of the MVP pattern we may start using it in our applications. However it may be not as easy. Maintaining an additional application logic layer may require considerable efforts. For example a developer needs to take care of linking between all views and appropriate controllers,

Fortunately MVC# automates and takes on itself much of the work concerned with MVP usage. Thus it simplifies and speeds up the development of MVP applications. Below is the list of MVC# framework features:

  • Views and controllers get connected automatically

    Developers do not have to care about associating views with their controllers. MVC# framework automatically establishes links between views and corresponding controllers:

    public class OrderDetailsView
        ...
       
    private void processOrderButton_Click(object sender, EventArgs e)
        {
           
    // No code needed to establish a link to the controller
            (Controller as OrderDetailsController).ProcessOrder();
        }
  • Multiple GUI platforms supported

    MVC# allows targeting different GUI platforms (Windows, Web, etc.) Thus the same application can be used with quite different presentation layers -one for Windows, the other for Web environment, etc.

Untitled-3.gif

  • Platform-independent navigation to views

    To make application logic fully independent of the presentation layer, MVC# provides a platform-independent way of navigating to views. Instead of  activating a Windows form or redirecting to a Web page a developer should simply call a uniform Navigator.Navigate() method:

    public class OrderDetailsController
        ...
       
    public void ProcessOrder()
        {
           
    // No Response.Redirect(...) or Form.Show() calls
            Task.Navigator.Navigate(OrderSupportTask.ProcessOrder);
        }
  • Tasks concept

    Another useful feature of MVC# framework, although not directly related to the MVP pattern, is the Task concept. A task unites several views with their controllers in fulfilling some job. For example a ticket booking task may consist of two views: one to choose a ticket, the other -to do the payment. In MVC# all controllers within a task are given a link to the task object. Generally a task can be expressed as a workflow or a state machine.

Untitled-4.gif

Conclusion

MVC# framework frees developers from much of extra work required in construction of Model-View-Presenter applications. It allows creating flexible MVP-based application with almost no extra cost. For more information on MVC# including the examples of using it see the project web site.


Login to add your contents and source code to this article
 [Top] Rate this article
 About the author
 
Oleg Zhukov
Oleg Zhukov, born and living in Russia is a software development consultant in a company which provides business IT solutions. He is studying computer science in Moscow Institute of Physics and Technology (MIPT) in department of system programming. He has got a B.A. degree in applied physics and mathematics and will graduate for M.A. this year. His research and development work concerns architectural patterns, model-driven development and systems analysis. Being the adherent of agile methods he applies them extensively in the projects managed by him.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other Visual Studio release. Work more productively and collaboratively-with greater control over your work at every step. The Beta 2 can give you a head start on achieving efficiency.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved