The adapter pattern
Download
1 / 7

The Adapter Pattern - PowerPoint PPT Presentation


  • 56 Views
  • Uploaded on

The Adapter Pattern. Scenario : An Existing System (your client code) interfaces to a Vendor Class library you purchased and incorporated into an application your company is currently selling. Existing System. Vendor1 Class. Vendor1 interface.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' The Adapter Pattern' - rasul


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
The adapter pattern

The Adapter Pattern

SE-2811

Dr. Mark L. Hornick


Scenario: An Existing System (your client code) interfaces to a Vendor Class library you purchased and incorporated into an application your company is currently selling

Existing System

Vendor1 Class

Vendor1 interface

The Vendor goes out of business; what do you do???


The original configuration
The original configuration

The ClientApp is writtensuch that it is heavily dependenton the functionality implementedin ServiceProvider, and is loadedwith calls to various ServiceProvidermethods.

ServiceProvider may implementnumerous methods in a real situation;not only the few methods shown here

SE-2811

Dr. Mark L. Hornick


Adapter wrapper pattern
Adapter (Wrapper) Pattern

Existing System

Vendor2 Class

  • Adapter

    • Implements the interface your classes expect

    • And talks to the vendor interface to service your requests.

Existing System

Vendor2 Class

Adapter


The adapter configuration
The Adapter configuration

2. An interface declaring the same methodsas the original ServiceProvider is created

3. A replacement classfor the original

ServiceProvider is found that providessimilar functionality,but with a differentset of methods: the adaptee

4. An adapter class is writtenwhich maps calls from the original methods to the new methods

1. The original ServiceProvider class is obsolete and discarded


The adapter pattern features
The Adapter Pattern features

  • The client makes a request to the adapter by calling a method on it by continuing to program to the interface that mimics the methods of the original class.

  • The adapter translates the request into one or more calls on the adaptee

    • The amount of code is usually small, but may be complex due to indirect mappings from the original methods to the new methods.

  • The adapter transforms data or results from the adaptee into the form expected by the client

    • The client receives the results of the call and doesn’t care that there is an adapter doing the translation.

    • The only change to the client is that it must create aninstance of the adapter rather than the original vendor class.


Cases to use adapter
Cases to use Adapter

  • Legacy code exists that interfaces to a class library that has changed

    • Revision change

    • Vendor change

  • New application is being developed that will have to interface to a class library that has yet to be defined

    • Define an interface and write the adapter later

SE-2811

Dr. Mark L. Hornick


ad