Adapter%20Pattern - PowerPoint PPT Presentation

About This Presentation
Title:

Adapter%20Pattern

Description:

For example, a plug made in Europe for a European outlet, may not fit in an outlet in the US. ... abstract class Student{ Target class. abstract void enroll ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 9
Provided by: uccsm
Category:

less

Transcript and Presenter's Notes

Title: Adapter%20Pattern


1
Adapter Pattern
  • This presentation will probably involve audience
    discussion, which will create action items. Use
    PowerPoint to keep track of these action items
    during your presentation
  • In Slide Show, hold down the control key and
    click the mouse button
  • Select Meeting Minder
  • Select the Action Items tab
  • Type in action items as they come up
  • Click OK to dismiss this box
  • This will automatically create an Action Item
    slide at the end of your presentation with your
    points entered.
  • by
  • Manish Shah Eugene Park
  • CSPP 523
  • Jan.21, 2002

2
Scenario
  • Outlets and Plugs
  • Outlets in the US require a certain type of
    plug.
  • For example, a plug made in Europe for a
    European outlet, may not fit in an outlet in the
    US.
  • To use this appliance in the US, one would need
    to purchase an adapter.

3
Overview
  • Structural Patterns
  • Patterns that describe how we can form larger
    structures from classes or objects.
  • The Adapter Pattern is a structural pattern which
    can be a class or an object pattern.
  • Class patterns use inheritance to compose
    classes.
  • Object patterns use object composition.

4
Lets Break it down...
  • This pattern lets classes work together that
    normally would not because their interfaces were
    incompatible.
  • Example TextShape and TextView

5
Structure of the Adapter Pattern
  • Object Adapter
  • Example
  • Target is Shape
  • Client is Drawing Editor
  • Adaptee is TextView
  • Adapter is TextShape

6
Structure of the Adapter Pattern
  • Class Adapter

7
Implementation
  • myStack Adapter Pattern is an Object Pattern
  • abstract class Stack
  • abstract Object top()
  • abstract Object pop()
  • abstract void push(Object v)
  • public class myStack
    Adapter class
  • private Vector stack new Vector()
    Adaptee object
  • public boolean empty() return stack.size()
    0
  • pubic Object top() return stack.lastElement()
  • public Object pop()
  • Object rslt stack.lastElement()
  • stack.removeElementAt(stack.size()-1)
  • return rslt
  • void push(Object v) stack.addElement(v)

Target class
8
Implementation continued
  • myStudent Adapter Pattern is a Class Adapter
  • abstract class Student
    Target class
  • abstract void enroll()
  • ...
  • public class ArchaicStudent
    Adaptee class
  • public void xyz()
  • ...
  • ...
  • public class myStudent extends ArchaicStudent
    Adapter class
  • public void enroll()
  • this.xyz()
  • ...
Write a Comment
User Comments (0)
About PowerShow.com