Patterns – Day 4 Interfaces and Adapter Reminders: Faculty candidate talks Monday and Thursday. No class on Monday.

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

02 - Structural Design Patterns – 1 Moshe Fresko Bar-Ilan University תשס"ח 2008.
18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
Patterns Reusable solutions to common object-oriented programming problems When given a programming problem, re-use an existing solution. Gang of Four.
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Patterns – Day 6 Adapter continued Reminders: Faculty candidate talk today 4:20 PM O-167. No class next Tuesday. Course newsgroup: rhit.cs.patterns.
ADAPTER PATTERN Ali Zonoozi Design patterns course Advisor: Dr. Noorhoseini Winter 2010.
Design Patterns William A. Hoffman NYU OOP Class.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Patterns – Day 5 Adapter Reminders: Faculty candidate talk Thursday. No class next Tuesday. Course newsgroup: rhit.cs.patterns.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Patterns.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Design Patterns in Java Chapter 1 Introduction Summary prepared by Kirk Scott 1.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Computing IV Singleton Pattern Xinwen Fu.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids.
Creational Patterns
What to know for the exam. Smalltalk will be used for questions, but there will not be questions about the grammar. Questions might ask – how particular.
CS616: Software Engineering Spring 2009 Design Patterns Sami Taha.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm.
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.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
CS 350 – Software Design The Adapter Pattern – Chapter 7 Gang of Four Definition: Convert the interface of a class into another interface that the client.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
S.Ducasse Stéphane Ducasse 1 Adapter.
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.
7 April 2004CSci 210 Spring Design Patterns 2 CSci 210.
TEMPLATE METHOD DESIGN PATTERN -SWAPNIL SHAH. WHAT IS A DESIGN PATTERN… A design pattern is a general reusable solution to a commonly occurring problem.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
Introduction with a few design patterns
Design Patterns with C# (and Food!)
object oriented Principles of software design
Software Engineering Lecture 7 - Design Patterns
by Manish Shah & Eugene Park CSPP 523 Jan.21, 2002
Adapter Pattern 1.
Informatics 122 Software Design II
Object Oriented Design Patterns - Structural Patterns
Design Patterns Part 2: Factory, Builder, & Memento
Structural Patterns: Adapter and Bridge
The Adapter Pattern.
Informatics 122 Software Design II
Chapter 8, Design Patterns Introduction
Chapter 8, Design Patterns Singleton
Adapter Pattern Jim Fawcett
Software Design Lecture 10.
Adapter Pattern Jim Fawcett
Presentation transcript:

Patterns – Day 4 Interfaces and Adapter Reminders: Faculty candidate talks Monday and Thursday. No class on Monday.

Quotes from James Cooper The [patterns] field has developed its own jargon. Some writing on this subject has been a bit obscure. Learning about Design Patterns entitles you to join an elite fraternity with its own language.

GoF Design Pattern Organization (slide by James Cooper) CreationalStructuralBehavioral Abstract FactoryAdapterChain of Responsibility BuilderBridgeCommand FactoryCompositeInterpreter PrototypeDecoratorIterator SingletonFacadeMediator FlyweightMemento ProxyObserver State Strategy Template Visitor

Metsker Design Pattern Organization InterfaceResponsibilityConstruction Abstract Factory Adapter Chain of Responsibility Builder BridgeCommand Factory Composite Interpreter Prototype Decorator Iterator Singleton Facade Mediator FlyweightMemento Proxy ObserverState Strategy Template Visitor OperationExtension

Interfaces Why do you think Metsker included this chapter that’s basically just about Java interfaces?

RocketSim interface

Interfaces imply responsibility?

Alternative approach

Solution to previous exercise

Adapter Pattern GoF Definition: Intent: Convert the interface of a class into another interface that clients expect. Adapter lets classes work together that otherwise couldn’t because of incompatible interfacer. Also known as Wrapper.

The next five slides are from Jim Cooper’s tutorial at OOPSLA Used with permission.

Let’s consider the Java awt.List and JList The awt.List is easier to use –But not very good looking –Hardly light weight public List(int rows) ; public void add(String item) ;String public void clear() ; public void remove(int position) ; public String[] getSelectedItems() ;String

JList is an improvement Better looking More flexible But much harder to use public JList(ListModel dataModel) ;JListListModel Everything else takes place in the data model.

Define a JawtList class Uses JList But has awt.List methods public interface awtList { public void add(String s); public void remove(String s); public String[] getSelectedItems(); public void clear(); }

Here is most of such a class //this is a simple adapter class to //convert List awt methods to Swing methods public class JawtList extends JScrollPane implements ListSelectionListener, awtList { private JList listWindow; private JListData listContents; public JawtList(int rows) { listContents = new JListData(); listWindow = new JList(listContents); listWindow.setPrototypeCellValue("Abcdefg Hijkmnop"); getViewport().add(listWindow); } // public void add(String s) { listContents.addElement(s); } // public void remove(String s) { listContents.removeElement(s); } // public void clear() { listContents.clear(); }

This is an Adapter pattern An adapter class converts the interface of one class to another. There are two ways to do this –Derive a new class from old one and add new methods (inheritance) –Create a class which contains old class and passes method calls to it. (object containment) These are called –Class adapters, and –Object adapters

Here is how we used it kidList = new JawtList(20); //=== private void loadList(Vector v) { kidList.clear(); Iterator iter = v.iterator(); while(iter.hasNext()){ Swimmer sw = (Swimmer) iter.next(); kidList.add(sw.getName()); }

GoF Example A Graphics toolkit may have a number of Shape objects that can be manipulated in a certain way (BoundingBox, CreateManipulator). There is no TextShape class, but there is TextView, which provides the needed functionality, but not the expected interface.

GoF general situation In Java, Target would probably be an interface. Target (Shape) defines the interface that client uses. Client (DrawingEditor) collaborates with objects conforming to the Target interface. Adaptee (TextView) defines an existing interface that needs to be adapted Adapter (TextShape) adapts the interface of Adaptee to the Target interface.

Is WindowAdapter an example of the Adapter pattern? More on Adapter Tuesday.