Chapter 3

download Chapter 3

of 17

description

Mohamad Firdaus bin Abd Rahman

Transcript of Chapter 3

Model-View-Controller (MVC)

Model-View-Controller (MVC)Model-View-Controller (MVC) ArchitectureModel-View-Controller architecture is all about dividing application components into three different categories Model, View and the Controller. Components of the MVC architecture has unique responsibility and each component is independent of the other component. Changes in one component will have no or less impact on other componentMVC- ModelModel is responsible for providing the data from the database and saving the data into the data store. All the business logic are implemented in the Model. Data entered by the user through View are check in the model before saving into the database. Data access, Data validation and the data saving logic are part of Model.

4

MVC- ViewView represents the user view of the application and is responsible fortaking the input from the user, dispatching the request to the controller and then receiving response from the controller and displaying the result to the user. HTML, JSPs, Custom Tag Libraries and Resources files are the part of view component.

6MVC- ControllerController is intermediary between Model and View. Controller is responsible for receiving the request from client. Once request is received from client it executes the appropriate business logic from the Model and then produce the output to the user using the View component. ActionServlet, Action, ActionForm and struts-config.xml are the part of Controller.

8MVC Architecture

How MVC works

10Example MVC in Java EE application

JAVA BeansWhat is a Java Bean?A Java Bean is a reusable software component that can be manipulated visually in a builder toolJavaSoftBeans PropertiesProperties are a Beans appearance and behaviour characteristics that can be changed at design time

By following specific naming conventions, the properties of a Bean that are revealed to the world can be identifiedConventions for Access MethodsSimple Properties:For a property of type Type and name Name:public Type getName( );public void setName(Type value);Boolean Properties:public boolean isName( );public void setName(boolean value);Bean MethodsA Bean may be implemented by a Java ClassThat Class contains a number of methods that may be used to access and control the BeanThese are generally all the public methods of the Class that implements the BeanAdvantages of Java BeansA Bean obtains all the benefits of Java's "write-once, run-anywhere" paradigm.

The properties, events, and methods of a Bean that are exposed to an applicationbuilder tool can be controlled.

A Bean may be designed to operate correctly in different locales, which makes ituseful in global markets.

The configuration settings of a Bean can be saved in persistent storage and restoredat a later time.

A Bean may register to receive events from other objects and can generate events thatare sent to other objects.