• 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

Class implements Listeners

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone.

Would there be any efficiency issues with having my class implement listeners:
i.e.


instead of creating separate listeners classes (or inner classes) and then adding them to my class:



Hopefully I made sense.
Thanks in advance
Vincent
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You wouldn't notice the efficiency difference. There might be a few milliseconds, but when you take maybe 0.3seconds to click a button, that is an imperceptible delay.

What I think you would notice, and I have fulminated about it on these fora before, is a maintenance overhead.

BTW: There is a link in the most recent Java Developers' Network newsletter to an interview with Brian Goetz. Goetz says you ought not to consider efficiency when coding at all; under "Write Dumb Code" he says we ought to write simple code and leave the efficiency and performance issues to the compiler.

If you get your outer class to implement several interfaces, you will end up with lots and lots of code like this:-which makes it very awkward to add (let alone remove) Components to the display.

Unless you have a Listener which listens to a Component as such (ComponentListener definitely, MouseMotionListener for positions of the mouse quite probably), in my opinion you are far better off with separate classes for the Listeners. Inner or outer, depending on whether you are planning to use them elsewhere.

CR
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic