Using the Adapter Pattern
page 3 of 8
by Brian Mains
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 35327/ 46

Introduction to the Adapter Pattern

The adapter pattern creates a common class interface for various sources that use a variety of interface definitions, as we have seen above. The specific implementations for "Books Express" and "I Luv Books" inherit from this interface, which acts as a connection between your application and the third-party application interfaces. That is the sole purpose of the adapter pattern; using the standardized interface in your application, it contains all the necessary third-party application code to do what it needs to do using the standard interface. Let us look at an example of the adapter classes for the two methods shown above.  Here we have the standard base adapter class for this example.

Listing 2

public abstract class BookAdapter
  public abstract Book RetrieveByISBN(string isbn);
  public abstract Book[] RetrieveBySearch(string searchText, bool anyTerms);

This base class defines the interface that the adapter classes will use. Let us take a look at the BooksExpressAdapter, which is the adapter used to connect to the "Books Express" repository and pull back book results. Notice that the adapter uses a Book class, not a BookItem or DataTable, to represent the book information. This is something unique to the local application and requires that a transformation of the data take place, which we will see later.

View Entire Article

User Comments

Title: Great !!   
Name: Gourik kumar Bora
Date: 2011-05-12 2:09:23 AM
thanks a lot Brian ....
Title: Excellent article   
Name: Chetan P
Date: 2008-08-18 6:01:55 AM
This is an excellent article i read about adapter pattern. I wish if it was given with UML diagrams, it would more appropriate to understand at a glance.
Title: Great   
Name: vishal
Date: 2007-12-05 12:54:21 AM
very easy to understand and really simple yet powerful post.
Title: good one   
Name: rakesh gurjar
Date: 2007-05-21 9:11:14 AM
nice to understand concept of adapter pattern

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-07-23 4:35:13 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search