IT Education PK


Welcome to IT Education PK

Model -- View/Controller Architecture

Thursday, December 2, 2010

A drawing pattern is a recurring solution that simplifies the design process. The thoughtful study of design patterns allows a developer to learn from the pioneering work of others. The M-VC design pattern is most important, I think, because it forces a programmer to completely rethink the approach to designing an application. The reward is reusable code. Since this is a hands on tutorial, I plan to show you how the M-VC architecture promotes code reuse by migrating a Windows Form solution to a browser based explanation using a Web Form.


The Model -- View/Controller architecture is a modification of the Model -- View -- Controller building used in the SmallTalk language. In the chitchat language, the application is divided into three parts. The Model encapsulates the application logic or algorithms. The View draws the presentation. The Controller responds to user or system events. The key concept is the separation of the application logic from the presentation and event handling code. The Model class is independent of the GUI and is ignorant of any implementation of the GUI. A good Model class should be able to function as part of a console application and support unit testing. In this chapter, you will build an application that separates the complex mathematics of a mortgage calculator (Model) from the presentation and event handling code (View/Controller). The code behind technique of Web Form programming further contributes to the separation of the View (HTML code) and Controller (code behind event handler) code.


Note: Unix programmers may recognize this pattern as INTERFACE-ENGINE.
Here is the graphical view of the mortgage calculator application using the M-VC architecture.
What's this?
There is no question that the complete separation of GUI code from the application logic is a difficult concept for many to grasp. It can be a painful learning experience as it forces a programmer to change the basic approach to application design. Many will fight the process, dragged into the new world of OOP kicking and screaming. But, when you see how much simpler a Model -- View/Controller application is to maintain or migrate, you will _see_ the light. I promise.

0 comments:

Post a Comment