Common design problems faced by seasoned and experienced developers helped in the creation of ‘Design Patterns’. One can reuse patterns across multiple applications. There are three types of design patterns which are Creational, Structural and Behavioral patterns. There is also fourth design pattern which is the J2EE design pattern and which is the basis of our post. We will discuss the Model-View-Controller, Front Controller and Intercepting Filter which are all part of the Web Component developer exam.
Model-View-Controller is the most popular design pattern. It has been around since the beginning of object oriented times. This design pattern involves separating the application into three components.
- The ‘model’ holds the data of the application. The ‘model’ is independent from the ‘Controller’ and ‘View’.
- The ‘View’ is the visible component of the web application. It displays the model data to the user and responds to user events – like click of a button.
- The ‘Controller’ reacts to user events generated by the user and is responsible for passing the model data to the ‘View’.
The key advantage of using the Model-View-Controller is that it reduces complexity and it makes “model class reusable without modification”. (Model View Controller Explained)
The Front Controller is most often used to handle requests and responses. Since most of the client server architecture is based on requests and responses the Front Controller plays a crucial role in diverting traffic to appropriate resources. It is like the traffic policeman directing traffic across an application.
An application may have one Front Controller or multiple Controllers. Most often the Front Controller is implemented as a Servlet. Each ‘Servlet Front Controller’ contains the list of URLs to be serviced mapped in its deployment descriptor. The Front Controller dispatches the request to appropriate resources.
In short, Front Controllers are used to:
- Control page flow and navigation
- Reduce duplication in JSP pages
- Handle business processing (Design Patterns and Frameworks)
After having seen the two design patterns – let us move onto the next pattern – the ‘Intercepting Filter’.The Intercepting Filter is one of the simplest design patterns based on the concept of ‘Filters’. Filters are the preferred method for functions similar to ‘RequestDispatchers’. Filters stand between the request and the resource and intercept the request and responses. They smoothen out the request/response and pass it to the resource or the client. They are also a class like servlets and implement the javax.servlet.Filter interface.
Since the ‘Intercepting Filter’ is based on the concept of Filters, it is also used when there is a lot of pre and post processing. One example may be to do some pre-processing before forwarding a request to a resource. Some common pre-processing of a client requests may be related to the authentication of the client, whether the client has a valid session, if the client’s IP address is coming from a trusted network and so on.
The primary advantage of using Intercepting Filters is that they are pluggable components to which code can be added or removed without affecting the main application in any way.
(Picture courtesy: http://www.javaskool.com/codeResources/J2EEDesignPatternChapters/j2eepatternPics/interceptor3.png)
We saw three popular design patterns which are related to the Web component developer certification in this post.
Bibliography Design Patterns and Frameworks. (n.d.). Retrieved from docs.oracle.com: http://docs.oracle.com/cd/E19818-01/817-2334/03_design_issues.html Model View Controller Explained. (n.d.). Retrieved from http://www.tomdalling.com/blog/software-design/model-view-controller-explained/
- Top 25+ Fresher Java Interview Questions - March 9, 2023
- 25 Free Practice Questions – GCP Certified Professional Cloud Architect - December 3, 2021
- 30 Free Questions – Google Cloud Certified Digital Leader Certification Exam - November 24, 2021
- 4 Types of Google Cloud Support Options for You - November 23, 2021
- APACHE STORM (2.2.0) – A Complete Guide - November 22, 2021
- Data Mining Vs Big Data – Find out the Best Differences - November 18, 2021
- Understanding MapReduce in Hadoop – Know how to get started - November 15, 2021
- What is Data Visualization? - October 22, 2021