What Is the MVC Pattern?


In the MVC pattern, three objects provide separation of application data and a presentation layer. The model maintains the application data and the business rules that govern manipulation of this data. The model is the closest of these objects to a real-world entity. Say you want to log in to a system. You want to allow different kinds of client applications to log in to the system, whether they use a desktop computer or a PDA. The model in this case is the interface to the underlying security technology, be it a database or an LDAP server. It parallels the security technology closely.

The view, on the other hand, has to understand the particulars of the display technology that it is rendering output for. If it is displaying output on a PDA, it will likely render the output in a much different way than if it is rendering for an HTML output device such as a standard browser.

Finally, the controller is the interface into the model. It helps to translate user interaction with the view into actions to be handled by the model. The controller may be somewhat different depending on what actions the view is capable of generating. The action may be an HTTP GET action when the user clicks a button on a browser, or it may be an HTTP POST from a Web service consumer.

The intention behind the MVC pattern is that even with consumers of the data as different as a PDA or a web service, the model remains essentially the same. It is insulated from client or consumer variations by the view and controller. It is thus better able to cleanly reflect the underlying real-world object or system. Many view and controller objects can front the same model object. Each view/controller pair is tuned for a particular type of consumer or client. A sample MVC diagram is shown in Figure 19.1.

Figure 19.1. A sample Model-View-Controller configuration.

graphics/19fig01.gif



BEA WebLogic Platform 7
BEA WebLogic Platform 7
ISBN: 0789727129
EAN: 2147483647
Year: 2003
Pages: 360

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net