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
-
S6 / 4.235 cc / 268 PS / 283 ft/lb (384 Nm) @ 4.000 / 0 - 62 mph (100 km/h): 10,4 s / Vmax: 123 mph (198 km/h) (click images for a larger ...
-
V8 / 4.395 cc / 555 PS / 502 lb/ft (680 Nm) @ 1.500 - 5.650 / biturbo / 0 - 62 mph (100 km/h): 3,9 s / Vmax: 193 mph (310 km/h) (click image...
-
Two years ago Tender Objects (or The Candy Twins as they were called back then...or was that a completely different band...I'm not sur...
-
With thanks to citizen contributor "Iain" for drawing our attention to one aspect of some disturbing developments. "Iain"...
-
Four hundred fifty electric Minis will hit the road in the next few weeks in California, New York and New Jersey. The leasees, who will have...
-
S4 / 1.390 cc / 180 PS - Engine of the year / 184 lb/ft (250 Nm) @ 2.000 - 4.500 / twincharger system (kompressor + turbo) / XDS front diff...
-
H ave not fully recovered - my voice is still a bit off-key (albeit a little sexy) and I'm still coughing like mad. I don't think an...
-
V12 / 5.576 cc / 385 PS / 406 ft/lb (550 Nm) @ 4.000 / 0 - 62 mph (100 km/h): 6,6 s / Vmax: 155 mph (250 km/h) (click images for a larger ...
-
We were really horrified and angry when, as we were sat inching forward in the heavy congestion on Aberdeen's world famous Union Street ...
-
To help promoting the release of new album Konkylie , When Saints Go Machine shares first single Kelly as a free download . Kelly by W...
No comments:
Post a Comment