The example services that we will use are two providers
within the sample application included with this article. The provider code
exists in the same application, but in reality it would be a reference from a Dynamic
Link Library (DLL), a web service reference or some other means. But, for
example purposes, let us look at two of the methods that would be commonly in
the service.
Listing 1
namespace BooksExpress
{
public class BooksProvider
{
public BookItem GetByISBN(string isbn){}
public BookItem[]Search(string searchText, bool anyTerms, bool
relativeMatching){}
}
}
namespace ILuvBooks
{
public static class BooksService
{
public static DataTable GetBookByISBN(string isbn){}
public static DataTable GetBooksBySearch(string searchText, bool anyTerms){}
}
}
The example above shows the code for the two fictitious companies
that we will be working with in this example: BooksExpress and ILuvBooks. As
you can see, these two providers implement different approaches. The first uses
a domain object to represent the book data, as well as using an instance of the
class to provide the book data. The second class uses more of a procedural
approach in creating a static class with static methods, returning a DataTable
to the caller. How do we calculate for this? Welcome the adapter pattern.