This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AWT

 
Richard Wilson
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An application consists of a set of user interfaces & the various
operations are to be performed based on the various user invoked
events. Which of the following are true for the above application
(a) Extending Adapter classes is not suitable
(b) Some listener interface must be implemented
(c) If a particular event listener is implemented only the methods of
interest to us need to be implemented
(d) Multiple event listeners can be added to a single component
(e) The order in which the events are processed is the order in which
the listeners are added
Ans:a,d
It is a quite strange why a is right?
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say b & d are correct. Where is this question from? I've learned that a lot of these test questions are just plain wrong.
I suppose a could be correct under certain conditions, but based on the really vauge description of the application, I can't see how extending adapter classes wouldn't be appropriate. If you use an adapter as an annonymous class, that's extending an adapter and this happens all the time.
So I also don't see why a is wrong.
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ans a would seem to be incorrect because the q say many events are to be handled by the app, in which case cluttering you code with many anonymous "adopter" classes that require to be overridded makes the code hard to read if not maintain.
Adapter classes don't provide any functionality, and since you need to define event handlers it seems absurd to use adapter classes that don't do anything.
[ February 18, 2002: Message edited by: Rajinder Yadav ]
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob I agree with you that the ans should also be b & d
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the contrary, adapter classes help keep your code uncluttered.
If you want to attach a mouse listener to a component, you could do this:

but if all you really want is to handle a mouseClicked event, this is a lot of typing. A MouseAdapter would be more useful in this case:
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob what I stated in my previous post was that if you need to define "many" of these handlers that the adapter class does nothing for, then having to define handle function that actually do something would result in cluttered hard to read code that uses adaptets which you end up defining/overriding the methods for.
Using your MouseListener, try to think of a realword app that actaully does something for each of these events, would you use adapter classes when each event required something to be done, I don't think you would, would you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic