Version 0.1
Copyright © 2007 Lars Vogel
01.07.2009
| Revision History | ||
|---|---|---|
| Revision 0.1 | 01.07.2009 | Lars Vogel |
| Separated from http://www.vogella.de/articles/DesignPatterns/article.html | ||
Table of Contents
The Adapter Pattern converts the interface of a class into another interface the clients expects. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
We have a database access class which provides the access to database tables and returns the data. This data should be displayed in a tree (either swing or swt). The table expects the data to be provided via a certain interfaces. Instead of adding this interface to the database access class (which would couples the GUI coding very tight to the database access class), we develop an adapter which converts the interfaces of the database access class to the interfaces of the tree.
By implementing an interface we can replace the adapter and or the underlying model easily which another adapter / model. Hence the application is loosely coupled.
Adapter allows to re-use existing coding without changing it. The adapter will make the conversion between the interfaces.
In comparison to a decorator the adapter pattern only converts interfaces, while the decorator pattern adds new functionality to an existing interface. Therefore the decorator does not change the existing interface.
Before posting questions, please see the vogella FAQ. If you have questions or find an error in this article please use the www.vogella.de Google Group. I have created a short list how to create good questions which might also help you.