• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface question

 
Jacky Luk
Ranch Hand
Posts: 634
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If I define cardReader as CSmartCard, I can make use of getOtherData();
if I define cardReader as IReader<CTimeRec>, can I make use of getOtherData();
If not, What should it be defined it as?
Thanks
Jack
 
Winston Gutkowski
Bartender
Pie
Posts: 9470
49
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack Luk wrote:If I define cardReader as CSmartCard, I can make use of getOtherData();

Yes.

if I define cardReader as IReader<CTimeRec>, can I make use of getOtherData();

No.

If not, What should it be defined it as?

That's entirely up to you; but given your code, I'd say probably a CSmartCard.

BTW: The use of initial 'I' and 'C' for your class/interface names is very old-fashioned. Maybe your course uses this notation, but you won't see it used often in the outside world (except perhaps in the Microsoft miniverse); and personally I find that it affects readability.

Winston
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:(except perhaps in the Microsoft miniverse)

Even there they only use the I prefix for interfaces. They don't use anything for concrete classes. (I found the 'I's a bit jarring at first, but you get used to it. The one that throws me swapping between C# and Java is List, which is an interface in Java and a concrete class in .NET).
 
Winston Gutkowski
Bartender
Pie
Posts: 9470
49
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:The one that throws me swapping between C# and Java is List, which is an interface in Java and a concrete class in .NET).

Ooof. Yes, I can imagine.

@Jack: I also notice that your program won't compile. You call cardReader.getData(), but in your entities it's defined as GetData().
Methods in Java should start with a lowercase letter.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic