By Shishir Kumar Contact:

Slides:



Advertisements
Similar presentations
Apache Struts Technology
Advertisements

Design Patterns Section 7.1 (JIA’s) Section (till page 259) (JIA’s) Section 7.2.2(JIA’s) Section (JIA’s)
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
ADAPTER PATTERN Ali Zonoozi Design patterns course Advisor: Dr. Noorhoseini Winter 2010.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Reuse Activities Selecting Design Patterns and Components
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
More OOP Design Patterns
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
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.
UNIT-V The MVC architecture and Struts Framework.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade pattern.
ADAPTER PATTERN BY Sravanthi Karumanchi. Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures.
1 GoF Template Method (pp ) GoF Strategy (pp ) PH Single User Protection (pp ) Presentation by Julie Betlach 6/08/2009.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 0 CSE3311 – Software Design Adapter Pattern.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Structural Design Patterns
Frameworks CompSci 230 S Software Construction.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
Review Class Inheritance, Abstract, Interfaces, Polymorphism, GUI (MVC)
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
Adapter and Façade Patterns By Wode Ni and Leonard Bacon-Shone.
The Template Method Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Pattern Bridge. Definition Bridge is the structural pattern that separates abstraction from the implementation so that both of them can be changed independently.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
Apache Struts Technology A MVC Framework for Java Web Applications.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns: MORE Examples
Servlets.
Design Patterns: Brief Examples
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
By SmartBoard team Adapter pattern.
Behavioral Design Patterns
Adapter Design Pattern
Satisfying Open/Closed Principle
Design and Maintenance of Web Applications in J2EE
Object Oriented Design Patterns - Structural Patterns
The Model Layer What is Model?
Structural Patterns: Adapter and Bridge
Strategy Design Pattern
Introduction to Design Patterns
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

By Shishir Kumar Contact:

 Decorator  Adaptor  Bridge  Template  Strategy

 Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

 AC Power Adapters Electronic products made for the USA cannot be used directly with electrical outlets found in most other parts of the world US 3-prong (grounded) plugs are not compatible with European wall outlets To use, you need either An AC power adapter, if the US product has a “universal” power supply, or An AC power convertor/adapter, if it doesn’t

 Object Adapters Object Adapters use a compositional technique to adapt one interface to another. The adapter inherits the target interface that the client expects to see, while it holds an instance of adaptee. Object adapters enable the client and the adaptee to be completely decoupled from each other. Only the adapter knows about both of them.  Class Adapters Class adapters use multiple inheritance to achieve their goals. As in the object adapter, the class adapter inherits the interface of the client's target. However, it also inherits the interface of the adaptee as well. Since Java does not support true multiple inheritance, this means that one of the interfaces must be inherited from a Java Interface type. Note that either or both of the target or adaptee interfaces could be an Java Interfaces. The request to the target is simply rerouted to the specific request that was inherited fro the adaptee interface.

 Difference between Object Adapters and Class Adapters  As Object Adapter uses composition it can not only adapt an adaptee class, but any of its subclasses. It is flexible.  Class Adapter is committed to only one adaptee. But again it has an advantage as no need to implement the entire adaptee. It can just override the behaviour of adaptee and also can override the behavior as it is sub classing.  Note that class adapters have a problem with name conflicts if methods of the same signature exist on both the target and the adaptee. Note that just because two objects have methods that have the same signature (syntax), it does not guarantee that the two methods have the same meaning or behavior (sematics). That is, the two methods do not necessarily map directly to each other. Object adapters do not have this problem.  Class adapters are simpler than object adapters in that they involve fewer classes and are useful if total decoupling of the client and adaptee is not needed.

 Client only understands the SquarePeg interface for inserting pegs using the insert() method. At back end application should reuse insert logic within round pegs?  One Way Adaptor (Object Adaptor)  Two Way Adaptor (Class Adaptor) Case Study II: Build web application where user input data from UI. Data can be saved within application database and/or routed to mainframe. Mainframe is proprietary system and we do not have control over same.

 The client makes a request on the adapter by invoking a method from the target interface on it  The adapter translates that request into one or more calls on the adaptee using the adaptee interface  The client receives the results of the call and never knows there is an adapter doing the translation

 We can not change the library interface, since we may not have its source code. Even if we did have the source code, we probably should not change the library for each domain-specific application  Sometimes a toolkit or class library can not be used because its interface is incompatible with the interface required by an application  You want to create a reusable class that cooperates with unrelated classes with incompatible interfaces  Implementation Issues How much adapting should be done? Simple interface conversion that just changes operation names and order of arguments Totally different set of operations

 Before Java’s new collection classes, iteration over a collection occurred via java.util.Enumeration hasMoreElements() : boolean nextElement() : Object  With the collection classes, iteration was moved to a new interface: java.util.Iterator hasNext(): boolean next(): Object remove(): void  There’s a lot of code out there that makes use of the Enumeration interface hence Iterator use Adaptor pattern

 Decouple an abstraction or interface from its implementation so that the two can vary independently

 Simulate Persistence API From application layer developer want to fetch information from persistence system. Persistence system can be RDBMS Database (can be any data base E.g. Oracle, Sybase or File System). In this scenario there are two interface a) Application layer – End client interact b) Persistence layer – Interface define persist/fetch

 Want to separate abstraction and implementation permanently  Hide implementation details from clients  Want to improve extensibility Real World Example:  DAO, Persistence Layer  Image (jpeg/png) display on different Operation System The image structure is the same across all operating systems, but the how it's viewed (the implementation) is different on each OS.

 The Template Method defines the steps of an algorithm and allows sub class to provide the implementation for one or more steps.  Template Method let subclass redefine certain steps of an algorithm without changing the algorithm’s structure.  Hook –behavior that can be overridden within subclass to control algorithm behavior.

 Application for processing flat file for a) Stock and b) Derivatives. Requirement  Stock support CSV format where as Derivative support txt  Stock data is separated by delimiter “,” where as Derivative data within Flat file separated by “|”. Data is persisted within database.  System can configure logging into system optionally for data under process.

 Want to have control over algorithm to avoid duplicate code  Use Template if you are aware of requirement complexity/algorithm. This is for code reuse and allow subclass to specify behavior. Real World Example:  Servlet (explained next slide)  Java – Arrays sort, mergeSort (Refer Head First Book)  JFrame – update() (Refer Head First Book)  HibernateCallback used in HibernateTemplate's execute(..) methods (Refer Spring Blogs)  Struts - RequestProcessor

 Servlet Life Cycle  init()  service()  destroy()  Service method is an abstract method in GenericServlet Class.  HttpServlet extends GenericServlet and implement service method.  Based on HTTP request type, HTTPServlet invokes  - doGet, doPost, doHead, doPut, doDelete, doTrace, doOptions  Developers extend HttpServlet and write meaningful method - doGet, doPost  Template - HttpServlet service method define template for handling HTTP requests.  Hollywood Principle - "Don't call me, I will call you“  Template method enforces "Open Closed principle". A class should be open for extension, but closed for modification.

 Strategy pattern defines a family of algorithms, encapsulates each one and makes them interchangeable.  Strategy lets the algorithm vary independently from clients that use it.  Subclasses decide how to implement steps in an algorithm.

 Application for processing flat file for a) Stock and b) Derivatives. Requirement  Validate File format/type against system configuration  Stock/Derivative data can be stored in database or content repository (as XML)  File can be routed to third party system Bloomberg (via SOAP) or other customer (JMS).  Investment Bank can do below action  Indus Bank: validate, store data (database) and route to Bloomberg  USB Bank: validate, store (Repo) and route to Bloomberg  ABC Bank: validate, store (DB) and route to other customer

 Operation:  Validate - common method to validate File format/type (independent of investment type – Stock/Derivative)  Parse and Store- parse data based on investment type (Stock/Derivative) and store within database or content repository system in XML format  Route – file to third party system (via SOAP) or Content repository system

 Many related classes differ only in their behavior  You need different variants of an algorithm  An algorithm uses data that clients shouldn't know about. Use the Strategy pattern to avoid exposing complex, algorithm-specific data structures.  A class defines many behaviors, and these appear as multiple conditional statements in its operations. Instead of many conditionals, move related conditional branches into their own Strategy class  Real World Example:  Swing GUI Text components  Java AWT

 Benefits  Provides an alternative to subclassing the Context class to get a variety of algorithms or behaviors  Eliminates large conditional statements  Provides a choice of implementations for the same behavior  Liabilities  Increases the number of objects  All algorithms must use the same Strategy interface