This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I just had to do a presentation on this so it is funny you asked: The difference is that an object adapter contains the adaptee while the class adapter inherits from the adaptee. Which to use is dependent on the specific requirements of your application. For example, if there are multiple adaptees, then you would use the object adapter. Here is some sample code. In this case the old class is called OldReporter (and has been converted into an interface), the new class (the adaptee) is called NewReportWriter, and the adapter is named ReportGenerator.
BTW, The GoF book does a nice job of explaining this pattern. [This message has been edited by Thomas Paul (edited March 22, 2001).]
No, the AWT adapter classes do have nothing in common with the GOF Adapter patterns - they are simply empty stub implementations of interfaces. In fact I don't know why the Sun programmers decided to call them adapters - it's awkward, in my humble opinion... Imagine you do have an Enumeration object and want to pass it to a method which expects an Iterator. You could do this by wrapping the Enumeration object into an implementation of the Iterator interface which just delegates calls to the appropriate methods of the Enumeration. That wrapper object would be an Object Adapter. Did that help?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus