• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wat are adapter classes ?

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

Can anyone make it clear the term adapter classes in context of java??

Hoping to hear from neone soon,
Saurabh
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Saurabh
Usually we use adapter classes when we have interfaces having many methods in there but we just need to override every method while using it. e.g.
WindowListener has many methods but if in our application we need only closingWindow() to implement what we have to do? Java enforces that we implement ALL methods in window listener interface. So, what we will end up
doing is- "write empty method implementation for those which don't care about". Now, this can become quite annoying if we have many such interfaces to
deal with, right? So, Java provides some inbuilt classes. e.g. WindowAdapter that implements all methods in WindowListener as empty implementation. Now, we can just say "extends WindowAdapter" and override just one method in our implementation.
This is the most specific use of Adapter classes I guess w.r.t. to AWT,Swing and all...
hth
maulin
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Notice that this is quite different from the Adapter design pattern!
In the adapter design pattern, you adapt the interface of a class/object, to the interface a client needs. For example, say you have a method which expects an Iterator as argument, but you only have an Enumeration. Than you could write an Adapter implementing the Iterator interface by delegating to the Enumeration.
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic