• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Interface question

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic