• Post Reply Bookmark Topic Watch Topic
  • New Topic

What are adapter classes and why are they used ?!!

 
Meghna ks
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
could somebody give me some info about this question?!!
Thanks
Meghna
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An adapter is a class that can be used instead of implementing a related interface. For instance for the AWT you can have a WindowListener with 7 methods that need to be implemented (bah humbug!). If you don't NEED all those methods and if you have not extended anything else, then you have the option of extending WindowAdapter instead. That allows you to just override the ONE method that you are going to use and inherit the other methods (much easier ).
Here is an article on adapters:
http://developer.java.sun.com/developer/TechTips/2000/tt0509.html#tip2
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are also pretty handy when you need an anonymous inner class to do something for you. For example, you can do something like this:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!