Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

List example

 
Dick Summerfield
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Here's the code for a List example taken from Just Java 2 Fifth Edition (that's the one that handles JDK 1.4 release) p. 460:

The author says: "we write an interface that has constants for the suit and rank of each card ... a class that holds four cards, inherits these constants by implementing the interface.

The example works fine and I've learnt a lot about Collections from expanding this example, but what's the point of that interface. If I delete the whole goldurn thing the program works just as well!!!
Can somebody please explain this?
I'm sure I must be missing something...
[ January 20, 2008: Message edited by: Dick Summerfield ]
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi -

No, you're not missing anything.

On pg 460, Mr. van der Linden says:
"[class 'Hand'] .. inherits these constants by implementing the interface."

But then he never bothers using any of the constants he went to the trouble of inheriting - he just declares some new constants, in String[] "example".

Great book; poor example.

'Hope that helps .. PSM
 
Dick Summerfield
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Santa Maria:
No, you're not missing anything.
... he never bothers using any of the constants he went to the trouble of inheriting - Great book; poor example.
'Hope that helps .. PSM

It certainly did, Paul - Thanks
I changed the code as follows:

... which I think illustrates the point, though I'd want to make it more readable somehow for everyday use
[ January 20, 2008: Message edited by: Dick Summerfield ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic