The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

"Thinking in Java" and nested interfaces

Hi,

I'm reading "Thinking in Java" by Bruce Eckel. I must say, he knows his stuff very well, but his writing is difficult to understand for non-native english speakers.

I've been reading the chapter about nested interfaces for the third time know, and I still don't understand what problem nested interfaces are supposed to solve ...

Can someone please show me an example where nested interfaces are a good solution ?

(same goes for inner classes too, actually)


Thanks,

J.
Jeroen Jacobs Send private email
Wednesday, October 24, 2007
 
 
I haven't read that book, but looking under the section "Nesting Interfaces",

http://www.faqs.org/docs/think_java/TIJ310.htm

...it says "This reveals a number of very interesting features", and then follows with a horrendously stupid piece of code and no mention of any features. (...that is, "features" as I understand the term, and not "trivia").
my name is here
Wednesday, October 24, 2007
 
 
The concurrency and GUI chapters will probably give you some usage cases for inner classes (anonymous or named).  I used the "inner threaded Worker class" bit from the concurrency chapter a while ago to speed up something here at work (a "daily" process that was taking almost thirty hours to complete; turned into around 45 minutes after the change).
son of anon
Wednesday, October 24, 2007
 
 
He shows an interesting example where a private nested interface is used to provide methods only usable by the same object type. I wouldn't do this in practice, though, since a package-private/private/protected method should be equivilant. You're still exposing details unnecessarily which can be accessed using reflection.

I've found nested interfaces useful when:
 - One file for lots of small, related interfaces (seen this, usually don't care for it)
 - Implementation detail, where you might have multiple strategies as (private) inner classes and use a private interface to generically handle them.

They aren't used too often and largely are for consistancy. They can be handy, of course, but I wouldn't dwell on it.
Benjamin Manes Send private email
Wednesday, October 24, 2007
 
 
His writing is difficult to understand for native English speakers as well.
Zach M. Send private email
Wednesday, October 24, 2007
 
 
Sorry, I need to bother you guys again regarding this topic.

I notice he uses private nested interfaces too...
I thought interfaces were always public ?
What's the difference?

Is there any website that explains this topic in understandable english and with an example that makes sense ?

Thank you,

J.
Jeroen Jacobs Send private email
Thursday, October 25, 2007
 
 
You are mixing two things here: Methods on an interface are always public methods. Now you can very well define a nested interface to be private.

Nested interfaces and classes can come handy if you know that your interface or class will only be usable with the containing class. For example, have a look at java.util.Map.Entry
Christophe Keller Send private email
Thursday, October 25, 2007
 
 
Oops, your right. It was private nested, and I even said so. :)  I kept thinking it was public.
Benjamin Manes Send private email
Thursday, October 25, 2007
 
 
Err, wait. Too early and too tired. Sorry, mine was fine and you were replying to a different post. thanks for no delete feature, Joel!
Benjamin Manes Send private email
Thursday, October 25, 2007
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz