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?
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.
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 ]
<a href="http://www.rajindery.com" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes
Joined: Jan 18, 2002
Rob I agree with you that the ans should also be b & d
Joined: Jan 07, 2002
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:
Joined: Jan 18, 2002
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!