• Post Reply Bookmark Topic Watch Topic
  • New Topic

interfaces nested within interfaces  RSS feed

 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, Hardcore Java by Robert Simmons Jr. told me that I should almost never have interfaces within interfaces, which sort of struck me, as I tend to use them a fair amount. The best example I can find is the following interface for a World:



For the duration of this project, all Worlds will have Things and SentientThings. These may be implemented in very different ways, but there will alway be Things with those methods, and SentientThings with those methods. Is this a proper use of interfaces within interfaces, or should i heed Robert Simmons Jr.?

Thanks,
Joe
[ May 22, 2004: Message edited by: Joseph George ]
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a 'World', to have 'Things', they needn't be defined inside 'World'.

A javax.JButton has a Text, which is of type 'String', but String isn't an inner class of 'JButton'.
 
sever oon
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes sir, I think you've confused the "has-a" relationship with "is-a". Extending an interface should be reserved for something that shares an "is-a" relationship with that interface. For example:



A collie "is a" dog.

Just because a World "has-a" thing, doesn't mean it "is-a" thing.

sev
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is why World deoesn't extend Thing, Oon.

And Wagner, of course they needn't be defined in World, but it seems rather tidy to me, since Things will only ever exist as defined within Worlds.
[ May 23, 2004: Message edited by: Joseph George ]
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
allthough I guess it's a question of packages.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!