Design Pattern – Adapter

The purpose of the adapter pattern is actually quite simple. It converts one interface to another one, thus making it possible for classes to work together where the interfaces are different.

Real World Example

Because it’s such a common pattern I had to think for a while before coming up with an example.

Say, our application has to export some data in various formats – excel, pdf etc. It would be quite likely that third party libraries for each of the formats have different interfaces. We could of course write a switch statement, but the better solution would be to wrap each of the third party libraries into a class that implements a common interface. Then all we have to do is resolve the wrapper based on the format. Since the wrapper would implement a common interface the task of exporting data become relatively simple

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: