{"id":13634,"date":"2015-10-12T10:00:28","date_gmt":"2015-10-12T10:00:28","guid":{"rendered":"https:\/\/www.whizlabs.com\/?p=13634"},"modified":"2020-09-01T07:07:35","modified_gmt":"2020-09-01T07:07:35","slug":"java-design-patterns","status":"publish","type":"post","link":"https:\/\/www.whizlabs.com\/blog\/java-design-patterns\/","title":{"rendered":"Java Design Patterns"},"content":{"rendered":"<p>Common design problems faced by seasoned and experienced developers helped in the creation of \u2018Design Patterns\u2019. One can reuse patterns across multiple applications. \u00a0There 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 <em>Web Component developer exam.<\/em><\/p>\n<p>&nbsp;<\/p>\n<h3>Model-View-Controller:<\/h3>\n<p>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.<\/p>\n<ul>\n<li>The \u2018model\u2019 holds the data of the application. The \u2018model\u2019 is independent from the \u2018Controller\u2019 and \u2018View\u2019.<\/li>\n<li>The \u2018View\u2019 is the visible component of the web application. It displays the model data to the user and responds to user events \u2013 like click of a button.<\/li>\n<li>The \u2018Controller\u2019 reacts to user events generated by the user and is responsible for passing the model data to the \u2018View\u2019.<\/li>\n<\/ul>\n<p>The key advantage of using the Model-View-Controller is that it reduces complexity and it makes \u201cmodel class reusable without modification\u201d.\u00a0(Model View Controller Explained)<\/p>\n<p><a href=\"https:\/\/www.whizlabs.com\/wp-content\/uploads\/2015\/10\/JavaDesignPatterns-1.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-13636\" src=\"https:\/\/www.whizlabs.com\/wp-content\/uploads\/2015\/10\/JavaDesignPatterns-1.png\" alt=\"JavaDesignPatterns-1\" width=\"256\" height=\"282\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Front Controller:<\/h3>\n<p>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. \u00a0It is like the traffic policeman directing traffic across an application.<\/p>\n<p>An application may have one Front Controller or multiple Controllers. Most often the Front Controller is implemented as a Servlet. Each \u2018Servlet Front Controller\u2019 contains the list of URLs to be serviced mapped in its deployment descriptor. The Front Controller dispatches the request to appropriate resources.<\/p>\n<p>In short, Front Controllers are used to:<\/p>\n<ul>\n<li>Control page flow and navigation<\/li>\n<li>Reduce duplication in JSP pages<\/li>\n<li>Handle business processing (Design Patterns and Frameworks)<\/li>\n<\/ul>\n<h3><\/h3>\n<h3>Intercepting Filter:<\/h3>\n<p>After having seen the two design patterns \u2013 let us move onto the next pattern \u2013 the \u2018Intercepting Filter\u2019.The Intercepting Filter is one of the simplest design patterns based on the concept of \u2018<em>Filters<\/em>\u2019. Filters are the preferred method for functions similar to \u2018RequestDispatchers\u2019. Filters stand between the request and the resource and intercept the request and responses. \u00a0They 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.<\/p>\n<p>Since the \u2018Intercepting Filter\u2019 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\u2019s IP address is coming from a trusted network and so on.<\/p>\n<p>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.<\/p>\n<p><a href=\"https:\/\/www.whizlabs.com\/wp-content\/uploads\/2015\/10\/JavaDesignPatterns-2.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-13637\" src=\"https:\/\/www.whizlabs.com\/wp-content\/uploads\/2015\/10\/JavaDesignPatterns-2.png\" alt=\"JavaDesignPatterns-2\" width=\"600\" height=\"329\" \/><\/a><\/p>\n<p>(Picture courtesy: <a href=\"http:\/\/www.javaskool.com\/codeResources\/J2EEDesignPatternChapters\/j2eepatternPics\/interceptor3.png\" target=\"_blank\" rel=\"noopener\">http:\/\/www.javaskool.com\/codeResources\/J2EEDesignPatternChapters\/j2eepatternPics\/interceptor3.png<\/a>)<\/p>\n<p>We saw three popular design patterns which are related to the Web component developer certification in this post.<\/p>\n<pre>Bibliography\n<em>Design Patterns and Frameworks<\/em>. (n.d.). Retrieved from docs.oracle.com: <a href=\"http:\/\/docs.oracle.com\/cd\/E19818-01\/817-2334\/03_design_issues.html\" target=\"_blank\" rel=\"noopener\">http:\/\/docs.oracle.com\/cd\/E19818-01\/817-2334\/03_design_issues.html<\/a> \n<em>Model View Controller Explained<\/em>. (n.d.). Retrieved from <a href=\"http:\/\/www.tomdalling.com\/blog\/software-design\/model-view-controller-explained\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.tomdalling.com\/blog\/software-design\/model-view-controller-explained\/<\/a><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Common design problems faced by seasoned and experienced developers helped in the creation of \u2018Design Patterns\u2019. One can reuse patterns across multiple applications. \u00a0There 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. &nbsp; Model-View-Controller: Model-View-Controller is the most popular design pattern. It has been around since the beginning of object oriented times. This design pattern [&hellip;]<\/p>\n","protected":false},"author":220,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[13],"tags":[967,978],"class_list":["post-13634","post","type-post","status-publish","format-standard","hentry","category-java","tag-java-3","tag-java-design-patterns"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"profile_24":false,"profile_48":false,"profile_96":false,"profile_150":false,"profile_300":false,"tptn_thumbnail":false,"web-stories-poster-portrait":false,"web-stories-publisher-logo":false,"web-stories-thumbnail":false},"uagb_author_info":{"display_name":"Aditi Malhotra","author_link":"https:\/\/www.whizlabs.com\/blog\/author\/aditi\/"},"uagb_comment_info":0,"uagb_excerpt":"Common design problems faced by seasoned and experienced developers helped in the creation of \u2018Design Patterns\u2019. One can reuse patterns across multiple applications. \u00a0There 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&hellip;","_links":{"self":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/13634","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/users\/220"}],"replies":[{"embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/comments?post=13634"}],"version-history":[{"count":1,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/13634\/revisions"}],"predecessor-version":[{"id":75987,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/posts\/13634\/revisions\/75987"}],"wp:attachment":[{"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/media?parent=13634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/categories?post=13634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.whizlabs.com\/blog\/wp-json\/wp\/v2\/tags?post=13634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}