IMPORTANT NOTICE TO STUDENTS These slides are NOT to be used as a replacement for student notes. These slides are sometimes vague and incomplete on purpose to spark class discussions JEE – Design Patterns Front Controller Intercepting Filter Transfer Object CS 446/646 ECE452 Jun 13th, 2011 WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE Overview JEE Core Design Patterns Presentation Tier Business Tier Integration Tier Intercepting Filter Business Delegate Data Access Object Front Controller Service Locator Service Activator Context Object Session Facade Domain Store App Controller Application Service Web Service Broker View Helper Business Object Composite View Composite Entity Service to Worker Transfer Object Dispatcher View TO Assembler Value List Handler WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 2 Front Controller Intent ● provide a single point for processing user requests http://java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 3 Front Controller Motivation ● single processing point for all client requests – – across views & session can be used to inject cross-cutting concerns ● ● – – logging security can we have multiple controllers? we can map multiple requests to the same controller? http://java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 4 Front Controller Motivation ● separation of concerns – business code from presentation code http://www.corej2eepatterns.com/Patterns2ndEd/FrontController.htm WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 5 Front Controller WATERLOO http://www.corej2eepatterns.com/Patterns2ndEd/FrontController.htm CHERITON SCHOOL OF COMPUTER SCIENCE 6 Front Controller Motivation ● provides resource mapping – physical ● – http://server/resource.jsp virtual/logical ● ● ● http://server/servlet/resourceController http://server/servlet/page1.help logical partitioning of application views? WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 7 Front Controller Motivation ● organic growth – controllers can be specialized (sub-classing) ● ● GWTServlet reusability – – – declarative vs. non-decalrative mapping what is declarative mapping? why do we care? WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 8 Intercepting Filter Intent ● common mechanism for pre & post processing of user requests WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 9 Intercepting Filter Filter chain request request request controller filter1 filter2 response response response how is this different from traditional pipes & filters? how is this different from batch pipes & filters? what type of data flows through the pipes? WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 10 Intercepting Filter Context ● “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”* Common Examples* ● has the client been authenticated? ● does the client have a valid session? ● is the client's IP address from a trusted network? ● does the request path violate any constraints? ● what encoding does the client use to send the data? ● do we support the browser type of the client? * http://java.sun.com/blueprints/corej2eepatterns/Patterns/InterceptingFilter.html WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 11 Intercepting Filter Easy Solution ● if-then-else in the controller (why not?) An Elegant Solution ● common reusable processing ● easy to add/modify/delete filtering functionality – even better if declarative WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 12 Intercepting Filter Sounds like Decorator (how?) WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 13 http://en.wikipedia.org/wiki/Decorator_pattern Intercepting Filter Sounds like Decorator http://msdn.microsoft.com/en-us/library/ff647251.aspx WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 14 Intercepting Filter WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE http://msdn.microsoft.com/en-us/library/ff647251.aspx 15 Intercepting Filter What is the different between the two? ● structure – FilterChain is no longer required ● runtime behaviour ● take another look at the diagram WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 16 Intercepting Filter WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE http://msdn.microsoft.com/en-us/library/ff647251.aspx 17 Intercepting Filter WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE http://msdn.microsoft.com/en-us/library/ff647251.aspx 18 Intercepting Filter Evolution WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 19 Intercepting Filter Evolution What is the impact of this? WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 20 Intercepting Filter Evolution What is the impact of this? WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 21 Intercepting Filter List some drawback of this design? WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 22 Intercepting Filter Motivation ● functionality injection ● improved reusability – ● filter chains can be defined in a number of ways declarative configuration Difficulties ● information sharing ● fault-tolerance WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 23 Transfer Object Intent ● to transfer multiple data elements over a tier getUserName() getUserAge() Client getUserPrefs() Business Component User Looks harmless?? http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 24 Transfer Object Solution ● use a Transfer Object to encapsulate the data http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 25 Transfer Object WATERLOO 26 CHERITON SCHOOL OF http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html COMPUTER SCIENCE Transfer Objects Scope & Complexity? ● ● ● can we have multiple types of transfer objects to represent data (a user)? create the transfer objects required how complex? WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 27 Transfer Object Consequences ● simplified remote interface ● fewer remote calls ● stale objects: very common problem for web apps – – ● what are stale objects? how would you deal with it? serialization over the wire? WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE 28
© Copyright 2024