Wednesday, December 5, 2007

The adapter pattern

The adapter pattern is easy to implement and makes it easier to connect to external data stores of varying types. It does not matter how the interfaces vary; you can easily create a common interface using the adapter pattern.
Using the adapter pattern makes interfacing with a variety of differing applications much easier. This pattern is especially useful when an application must connect to multiple external applications that differ in their requirements.
With a myriad of API's available in business systems, programs (like Microsoft Word), web services, etc., there are many different interfaces a developer has to understand to tie them all together into one business solution that he or she may be developing. For instance, maybe an application needs to connect to credit card service gateways to verify a customer's credit limit or to run a debit against the account. An application could connect to a health insurance provider to bill them for services provided. An application could display maps from varying map providers.

One thing that is certain with tying in various business systems is that the API's a developer uses will be different. There is not any standard interface across the industry for implementing a certain type of system, but there is good reason for you to want to do so. Uniformity in application development makes maintenance and documentation easier and makes the application design better.
However, with these varying systems, how can one tie together all of these interfaces into one common one? This is where the adapter pattern comes into play.


A very nice example I found here