This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Interface question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Interface question" Watch "Interface question" New topic
Author

Interface question

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 198


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

Joined: Mar 17, 2011
Posts: 4724
    
    7

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


Isn't it funny how there's always time and money enough to do it WRONG?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3786
    
    1

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

Joined: Mar 17, 2011
Posts: 4724
    
    7

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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Interface question
 
Similar Threads
Don't understand why?
put arraylist in session?
Doubt Reg: initializing Variables with method call
The usage of Java Interfaces
Displaying data in a table that lies in a container tree.