Model. It represents enterprise data and the business rules that govern View. It renders the contents of a model. It accesses enterprise data Controller. It translates interactions with the v

J.E.D.I

4.3.1 Model-View-Controller Design Pattern

Problem Enterprise applications need to support multiple types of users with multiple types of interfaces. For one application, it may require an HTML from for web customers, a WML from for wireless customers, a Java Swing Interface for administrators, and an XML- based Web services for suppliers. The forces behind this pattern are as follows: • The same enterprise data needs to be accessed by different views. • The same enterprise data needs to be updated through different interactions. • The support of multiple types of views and interactions should not impact the components that provide the core functionality of the enterprise application. Context The application presents contents to users in numerous pages containing various data. Solution The Model-View-Controller MVC is a widely used design pattern for interactive applications. It divides functionality among objects involved in maintaining and presenting data to minimize the degree of coupling between the objects. It divides the application into three, namely, model, view and controller.

1. Model. It represents enterprise data and the business rules that govern

access to and updates to this data. It serves as a software approximation of real-world process, so simple real-world modeling techniques apply when defining the model.

2. View. It renders the contents of a model. It accesses enterprise data

through the model and specifies how that data is presented to the actors. It is responsible for maintaining the consistency in its presentation when the underlying model changes. It can be achieved through a push model, where the view registers itself with the model for change notifications or a pull model, where the view is responsible for calling the model when it needs to retrieve the most current data.

3. Controller. It translates interactions with the view into actions to be

performed by the model. In a stand-alone GUI client, it can be clicks on buttons or menu selections. For Web application, they appear as GET and POST HTTP requests. The actions performed on the model can be activating device, business process or changing the state of a model. Figure 4.21 shows the Model-View-Controller Design Pattern. Software Engineering 156 J.E.D.I The strategies by which MVC can be implemented are as follows: • For Web-based clients such as browsers, use Java Server Pages JSP to render the view, Servlet as the controller, and Enterprise JavaBeans EJB components as the model. • For Centralized controller, instead of having multiple servlets as controller, a main servlet is used to make control more manageable. The Front-Controller pattern can be a useful pattern for this strategy. Software Engineering 157 Figure 4.21 Model-View-Controller Design Pattern MODEL -represents enterprise data -represents business rules -maintains application states CONTROLLER -defines application behavior -routes user commands to Model updates -selects Views for presentation VIEW -renders the Model -accesses enterprise data -relays user actions to the Controller Query State Change State Select View Notify Changes User Actions Method Call Event J.E.D.I

4.4 Data Design