DA-YEH University CSIE Pattern-Oriented Design The Dynamic Mapping Design Pattern Author : J. Gresh J. McKim J. McKim H. Sanchez H. Sanchez Excerpt From.

Slides:



Advertisements
Similar presentations
And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering.
Advertisements

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Chapter 8Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 8 l Basic Exception Handling »the mechanics of exceptions l.
COMP 321 Week 8. Overview MVC Example Servlet Lifecycle Servlet Mechanics MVC Lab 5-2 Solution Lab 8-1 Introduction.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
Servlets and JDBC. Servlets A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password:
J2EE Servlets and JSP Advanced topics Presented by Bartosz Sakowicz.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password:
Integrating Servlets and JavaServer Pages Vijayan Sugumaran School of Business Administration Oakland University Parts of this presentation provided by.

Chinese New Year is the first day of the lunar calendar, so it is also called the Lunar New Year. And it is also referred to as the Spring Festival since.
Servlets Life Cycle. The Servlet Life Cycle A servlet life cycle can be defined as the entire process from its creation till the destruction. The following.
CSCI 6962: Server-side Design and Programming History and Background.
Lecture 2 - Struts ENTERPRISE JAVA. 2 Contents  Servlet Deployment  Servlet Filters  Model View Controllers  Struts  Dependency Injection.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Copyright © 2003 ProsoftTraining. All rights reserved. Distributed Object Computing Using Java and CORBA.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
Exception Handling in Java Exception Handling Introduction: After completing this chapter, you will be able to comprehend the nature and kinds.
Session Beans Overview EJB container Remote Invocation Represent client's access to app Local / Remote speed / flexibility trade-off when to choose local.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
SUN J2EE Architecture (Introduction, J2EE Patterns, Samples)
JSP Architecture Outline  Model 1 Architecture  Model 2 Architecture.
CGS – 4854 Summer 2012 Web Site Construction and Management Instructor: Francisco R. Ortega Chapter 2.
CGS – 4854 Summer 2012 Web Site Construction and Management Instructor: Francisco R. Ortega Chapter 3 Part 1.
Java Servlets. Servlets When we run small Java programs within a browser these are referred to as Applets... And when we run small Java programs within.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
By: Isabella Ruiz (Jiang Mei Yun).  Dates: 1989, 1977, 1965  The Snake.
이경화 Ch13. 웹 프로그래밍 설계 및 실습 MVC2 Member.
Domain Driven Web Development With WebJinn Sergei Kojarski College of Computer & Information Science Northeastern University joint work with David H. Lorenz.
CSC 2720 Building Web Applications Frameworks for Building Web Applications.
CS 160: Software Engineering October 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
 Obtaining a RequestDispatcher Forwarding requests from servlets to dynamic resources  Forwarding requests from servlets to static resources  Using.
Top right corner for field-mark, customer or partner logotypes. See Best practice for example. Slide title 40 pt Slide subtitle 24 pt Text 24 pt Bullets.
Computer Programming with JAVA Chapter 8. Exception Handling Basic Exception Handling the mechanics of exceptions Defining and Using Exceptions some "simple"
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
©SoftMoore ConsultingSlide 1 Filters. Filters can be used in a web application to intercept, examine, and possibly transform requests or responses associated.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Chinese New Year 新年好 Xīn nián h ǎ o! Happy New Year!
The Template Method Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Vakgroep Informatietechnologie – Onderzoeksgroep (naam) Web Centric Design of Distributed Software.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Introduction To HTML Dr. Magdi AMER. HTML elements.
ClaRA web services V. Gyurjyan Clas12 Software Meeting
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
CS 350 – Software Design The Decorator Pattern – Chapter 17 In this chapter we expand our e-commerce case study and learn how to use the Decorator Pattern.
Chineses Zodiac. The Chinese Zodiac is based on a twelve year cycle, each year being represented by an animal.
OOSD Using Java CBTS Framework. 11/2/04CBTS2 Servlet  A servlet is a Java program that can extends Web server’s functionality.  Servlets interact with.
Chinese Zodiac. What we are going to learn? Getting to know how to read,write and the meaning of the new words about Chinese Zodiac.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Enterprise Java v050228MVC1 Model, View, Controller Web Architecture.
Struct-like structure. Controller extends HttpServlet //Process the HTTP Get request public void doGet(HttpServletRequest request, HttpServletResponse.
Modern Programming Tools And Techniques-I
Java Servlets By: Tejashri Udavant..
Inheritance and Polymorphism
State pattern – A logical ‘Finite State Machine’
null, true, and false are also reserved.
Java Programming Language
In Class Assg 2 - solution
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Basic servlet structure
Presentation transcript:

DA-YEH University CSIE Pattern-Oriented Design The Dynamic Mapping Design Pattern Author : J. Gresh J. McKim J. McKim H. Sanchez H. Sanchez Excerpt From : PLoP 2005 conference reader: E Shine Liang

2 Outline Overview Introducing the Bridge Pattern Learning the Dynamic Mapping Pattern: An Example An Observation About Using Design Patterns Learning the Dynamic Mapping Pattern: Deriving It Field Notes: Using the Dynamic Mapping Pattern

3 Overview A design pattern for the elimination of lengthy conditional statements named Dynamic Mapping. uses a collection of objects that implement a common interface and dynamic class loading to replace lengthy domain specific conditional logic.

4 Outline Overview Introducing the Dynamic Mapping Pattern Learning the Dynamic Mapping Pattern: An Example An Observation About Using Design Patterns Learning the Dynamic Mapping Pattern: Deriving It Field Notes: Using the Dynamic Mapping Pattern

5 Introducing the Dynamic Mapping Pattern Intent Use a language's underlying class loading mechanism to eliminate explicit domain specific mappings. Use a language's underlying class loading mechanism to eliminate explicit domain specific mappings.

6 Outline Overview Introducing the Dynamic Mapping Pattern Learning the Dynamic Mapping Pattern: An Example An Observation About Using Design Patterns Learning the Dynamic Mapping Pattern: Deriving It Field Notes: Using the Dynamic Mapping Pattern

7 Problem of the Strategy Pattern How to create CalcTax How to create CalcTax CalcTax* calc_tax = null; If (buyer_country == US) calc_tax = new USTax(); else if (buyer_country == CANADA) calc_tax = new CANTax(); else if (…) calc_tax = new … endif If (calc_tax != null) { float tax_amount = calc_tax >calc(); } Learning the Dynamic Mapping Pattern :An Example

8 Lengthy conditional statements public Animal getAnimal(String name) { if ("Rat".equals(name)) return new Rat(); else if ("Ox".equals(name)) return new Ox(); else if ("Tiger".equals(name)) return new Tiger(); else if ("Rabbit".equals(name)) return new Rabbit(); else if ("Dragon".equals(name)) return new Dragon(); else if ("Snake".equals(name)) return new Snake(); else if ("Horse".equals(name)) return new Horse(); else if ("Ram".equals(name)) return new Ram(); else if ("Monkey".equals(name)) return new Monkey(); else if ("Rooster".equals(name)) return new Rooster(); else if ("Dog".equals(name)) return new Dog(); else if ("Pig".equals(name)) return new Pig(); return null; }

9 Language's underlying class loading mechanism Class.forName(fullName).newInstance(); Class.forName(fullName).newInstance(); public static final String ANIMAL_PACKAGE_NAME = "POD.MappingFactory.animal"; public Animal getAnimal(String name) { String fullName = ANIMAL_PACKAGE_NAME + "." + name; try { return (Animal) Class.forName(fullName).newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return null; } Learning the Dynamic Mapping Pattern :An Example

10 Learning the Dynamic Mapping Pattern :An Example Sequence diagram

11 demonstrate JAVA JAVAEclipse3 POD.MappingFactory.animal.client.java; POD.MappingFactory.animal.client.java; C++ C++ ”Dynamic Class Loading for C++ on Linux ” by James Norton void *hndl = dlopen("libnewshapes.obj", RTLD_NOW); if(hndl == NULL) if(hndl == NULL){ cerr << dlerror() << endl; cerr << dlerror() << endl; exit(-1); exit(-1); } void *mkr = dlsym(hndl, "maker"); void *mkr = dlsym(hndl, "maker"); Learning the Dynamic Mapping Pattern :An Example

12 A Controller Servlet written using Dynamic Mapping Pattern Learning the Dynamic Mapping Pattern :An Example

13 Sequence Diagram of the servlet and JSP Learning the Dynamic Mapping Pattern :An Example

14 Lengthy conditional statements Learning the Dynamic Mapping Pattern :An Example public class ControllerTradition { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String operation = request.getParameter("operation"); if (operation == null) { operation = "unknown"; } String address = ""; if (operation.equals("Rat")) { address = "/WEB-INF/Rat.jsp"; } else if (operation.equals("Ox")) { address = "/WEB-INF/Ox.jsp"; } else if (operation.equals("Tiger")) { address = "/WEB-INF/Tiger.jsp"; } else if (operation.equals("Rabbit")) { RequestDispatcher dispatcher = request.getRequestDispatcher(address); dispatcher.forward(request, response); }

15 Learning the Dynamic Mapping Pattern :An Example public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { processRequest(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { processRequest(request, response); } protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ActionInterface action = null; String actionName = mPrefix + request.getParameter(mActionName) + mPostFix; try { action = (ActionInterface) Class.forName(actionName).newInstance(); action.processRequest(request, response); RequestDispatcher disp = request.getRequestDispatcher(action.getNextUrl()); disp.forward(request, response); } catch (Throwable t) { throw new ServletException(t); }

16 Outline Overview Introducing the Dynamic Mapping Pattern Learning the Dynamic Mapping Pattern: An Example An Observation About Using Design Patterns Learning the Dynamic Mapping Pattern: Deriving It Field Notes: Using the Dynamic Mapping Pattern

17 An Observation About Using Design Patterns Use of the Dynamic Mapping design pattern eliminates any representation of a lengthy conditional created and maintained by the authors of a system. The Dynamic Mapping design pattern defers this responsibility to the underlying language by using dynamic class loading and thereby reduces the number of potential errors that can be generated, reduces the amount that the system will grow, and adds additional opportunities for reuse.

18 Outline Overview Introducing the Dynamic Mapping Pattern Learning the Dynamic Mapping Pattern: An Example An Observation About Using Design Patterns Learning the Dynamic Mapping Pattern: Deriving It Field Notes: Using the Dynamic Mapping Pattern Summary

19 Generic structure of the Dynamic Mapping pattern Field Notes: Using the Dynamic Mapping Pattern

20 Learning the Dynamic Mapping Pattern: Deriving It Interface Defines the interface of the objects created by the Factory Defines the interface of the objects created by the Factory Defines methods that can be executed by either the Factory or the Client Defines methods that can be executed by either the Factory or the Client

21 Learning the Dynamic Mapping Pattern: Deriving It Factory Performs the action requested by the client Performs the action requested by the client Determines what action to take based upon the specification provided by the client Determines what action to take based upon the specification provided by the client Can execute one or more methods of the Interface Can execute one or more methods of the Interface May or may not return an instance of the Interface. May or may not return an instance of the Interface. May or may not return an instance of some other class. May or may not return an instance of some other class. Does not use domain specific mappings. Does not use domain specific mappings.

22 Learning the Dynamic Mapping Pattern: Deriving It Implementation Concrete definition of the Interface. Concrete definition of the Interface.Client Makes requests to the Factory for a specific action. Makes requests to the Factory for a specific action. Known Uses Can be used in association with Factory patterns and Controller patterns. Can be used in association with Factory patterns and Controller patterns.

23 Outline Overview Introducing the Dynamic Mapping Pattern Learning the Dynamic Mapping Pattern: An Example An Observation About Using Design Patterns Learning the Dynamic Mapping Pattern: Deriving It Field Notes: Using the Dynamic Mapping Pattern Summary

24 Field Notes: Using the Dynamic Mapping Pattern Dynamic mapping provides the dvantages Reduction of errors Reduction of errors The potential for errors that can occur through the use of domain specific mappings is reduced Constant Size Constant Size Domain specific mappings will grow linearly with the number of mappings that are required Reuse Reuse Use of the Dynamic Mapping design pattern produces classes that are highly reusable

The End