Throughout the years of promoting Layered Architecture on .NET, I have occasionally came across the question on how to integrate the Model-View-Controller (MVC) Architecture into Layering. MVC provides clear separation of data and UI logic concerns coupled with the benefits of high testability. Layered Architecture provides a scalable, extensible, maintainable and highly adaptable distributed design for applications. With such advantages from both architectures, who can resist them? :)
Back then, there weren't any sophisticated MVC tools in Visual Studio, the closest was the Smart Client Software Factory (SCSF) and Web Client Software Factory (WCSF), but both were using rather complicated implementations. But today, VS 2010 provides us with ASP.NET MVC web application templates which effectively raises the need to answer the integration question even further.
Before I discuss the integration ideas, I would like to first share with you my personal perspective of the MVC architecture. Firstly, MVC is an out-dated (but good) architecture. Many sites will tell you that MVC is not new and it has been around since SmallTalk. Why I say it is out-dated is because it was not designed for today's service-oriented distributed architectures (something that can be fixed when merged with Layering).
Secondly, I view MVC as a "micro-pattern" for developing UI applications and Layering as a "macro-pattern" that can house multiple micro-patterns (not just limited to MVC). Therefore, I truly believe that MVC can be integrated into Layering to leverage on modern day distributed environments.
Finally, I felt that the out-of-the-box ASP.NET MVC templates in VS2010 are encouraging a monolithic approach. Ok, I admit that I think most of the OOTB VS templates are *evil*, simply because their focus is on RAD and promoting the adoption of a specific technology without looking at the complete architecture. Some developers have already realized this and have started to decouple their Data Layers to a Data Service, but that still leaves them with a "client/server application" at best. Do take note that all these problems I highlighted are not the fault of the developers but more on the project templates.
I shall reserve my ideas to fix those templates to another post, but right now, I will provide the high-level concepts of merging the two architectures to get the best of both worlds. There are two models which I have came up with and I will start off with the first one which I conveniently termed it as the Bridged Model.
If we dissect both architectures, we can easily identify components of similar responsibilities regardless of the term that is used. In MVC, the Model is used to ferry data, the View is used to display/capture data and the Controller is used to process logic and co-ordinate the flow between Views. In Layered Architecture, the Business Entities are used to ferry data, UI Components are used to display/capture data and the UI Process Components are there to co-ordinate the UI (and connect to the service back-end) - Notice the similarities?
In the Bridged Model, the key to connecting both architectures lies in the Controller component of the MVC and the UI Process Component (UIPC) of the Layered Architecture. By connecting the Controller to the UIPC, we treat the entire MVC portion as a UI layer (or component) sitting on top of the UIPC. This strategy has the benefit of making the Controller more lightweight as most of the application and service-communication logic is delegated to the UIPC. It is also good for multi-UI platform applications which may allow Desktop, RIA and mobile clients to share the same UI processing logic.
If you are integrating a MVC web application to an application with existing UI components calling a service back-end, then the Bridge Model will make most sense.
While the Bridge Model works in connecting the two architectures, it may seem less elegant if we only have a single UI platform. In that case, we may not want the performance overhead of the Controller-UIPC relationship and to remedy it, we can adopt the Integrated Model.
In the Integrated Model, the Presentation Layer components are being replaced completely with the MVC components. The responsibility of the UIPC is unified into the Controller, eliminating one level in the UI and therefore, improving the performance of the application.
Whether to use the Bridge Model, Integrated Model or not at all, is depending on your choice and the projected application growth. If you are dead-sure that your application will not grow, then the monolithic approach presented by the OOTB templates will work just fine. Otherwise, if you share the same thoughts like me i.e. "All applications has the potential to grow, no matter how small they are", then it may be wise to look at the integration models from the start.
Take note that although I used Web Application in the context of the discussion, these concepts can be equally applied to any type of MVC application i.e. the SCSF implementation of MVC/MVP.
[Update: You can now get a sample of MVC integrated to Layered Architecture here]
Home » Windows Workflow Foundation » MVC and Layered Architecture
MVC and Layered Architecture
19:28
Jurnalis Jalanan
Labels:
.NET,
ASP.NET MVC,
Layered Architecture,
Visual Studio,
Web Development,
Windows Communication Foundation,
Windows Workflow Foundation
Popular Post
-
V8 / 3.523 cc / 335 PS / 381 lb/ft (517 Nm) @ 3.650 / supercharger (click images for a larger view)
-
On Wednesday, August 29, TMC Fuel Injection System LLC filed a lawsuit in the U.S. District Court in Philadelphia against Ford Motor Compan...
-
found on http://www.53deluxe.com/everything-else/9208/little-big-shot/ via http://www.chromjuwelen.com/de/network/317/158411-little-big-sh...
-
As one of the most successful (and dare we say, most beautiful) Alfa Romeo sedans of modern times, the 156 is anything but rare – just as l...
-
Chinese media have discovered a completely undisguised prototype of what is deemed a facelifted version of the Peugeot 3008 crossover that ...
-
it was built by buying a Mercedes 300sl, and recreating the chassis with a tube frrame, and mounting the Corvette racing gear to that. Magne...
-
Photo: Diane Edwardson, February 9, 2012. The 6 vacant lots in question are to the left (downslope) of the police activity on Rosebud Av...
-
The first supercar to come from Slovenia, the Tushek Renovatio T500, will receive its UK debut at the 2012 edition of the Salon Privé on Se...
-
The Ford group is eying China's lucrative luxury car segment as it announced plans today to launch its Lincoln brand in the country in t...
-
McLaren had quite a presence at this past weekend’s Pebble Beach Concours d’Elegance on Monterey, California, as the British automaker showe...



No comments:
Post a Comment