This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Naming Interfaces

 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Recently a colleague of mine shows me a sample of his program. I want to copy part of his module
so that I wont have to rewrite it myself..(lazy but effective I think)

But I was caught with how he names his interfaces, it always starts with IBladeTrans, IScrewTrans etc...

For once, it is easier to know which one is interface and which one is abstract.
I am not sure but I feel awkward with this. Do you think this will be OK?

Any thoughts?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64696
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ick.

That's a convention from C++.

I didn't like it then, and I like it even less for Java.

I just name them whatever makes sense.
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you may want to refer this,
http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html
I have heard about the "IXXX" convention, but sun does not say so
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Ick....I just name them whatever makes sense.


+1
Having an name which immediately tells you something about the class is always helpful. e.g. AbstractTableModel tells me the class is abstract and it implements the TableModel interface.
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Maneesh, ye "ick" kya hota hai ??
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Ick.
...

What does 'ick' mean Bear ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64696
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:What does 'ick' mean Bear ?

Imagine that you've accidentally put your hand in something wet and gooey and gross. You say "Ick!"
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm, and i went crazy searching for that acronym
so, I guess its a slang form of "yuck"
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:
Bear Bibeault wrote:Ick....I just name them whatever makes sense.


+1
Having an name which immediately tells you something about the class is always helpful. e.g. AbstractTableModel tells me the class is abstract and it implements the TableModel interface.

+2
 
Mike Simmons
Ranch Hand
Posts: 3036
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:hmm, and i went crazy searching for that acronym
so, I guess its a slang form of "yuck"

I would say that "yuck" and "ick" are both equally slang forms of each other. Neither is formal English; both are slang.
 
Mike Simmons
Ranch Hand
Posts: 3036
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:
Bear Bibeault wrote:Ick....I just name them whatever makes sense.


+1
Having an name which immediately tells you something about the class is always helpful.

Well, names like IBladeTrans and IScrewTrans are useful in that respect - they immediately tell you that they are interfaces.

(Assuming you care.)

That seems to be antithetical to what Bear was saying. He doesn't want to worry about whether a given class or interface is a class, or abstact class, or interface. Most of the time at least. Not as part of the name. (And I agree with Bear on this point.)

So, Maneesh, when you say "+1", are you agreeing with Bear? (And me?) Or do you disagree? So far, I really can't tell.

Rob, when you say "+2", same question.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree on not liking the I... convention. I also agree about having sensible names.
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:
That seems to be antithetical to what Bear was saying. He doesn't want to worry about whether a given class or interface is a class, or abstact class, or interface. Most of the time at least. Not as part of the name. (And I agree with Bear on this point.)


Quite frankly i never want to differentiate my interfaces from my classes in terms of naming conventions. I wonder whats the cause of doing so.
Putting it the other way around :


isnt it great to leave it to abstraction that the pfile is a class or an interface ? You dont care, it has a print method that's all you care

or would you rather prefer:


or :


 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:Well, names like IBladeTrans and IScrewTrans are useful in that respect - they immediately tell you that they are interfaces.


i Agree on this
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:



I prefere this. PrintableFile is a Class which implements IPrintableFile Interface . is it make sense ?

salvin francis wrote:




Never do this [dont restrict the parameter type to a specific implementation]. and remember one thing that always prefere inteface type parameter to particular class type parameter
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would really really prefer to allow an interface there rather than a class.
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
btw what i did was a classic example of Using an Interface as a Type
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:
Maneesh Godbole wrote:
Bear Bibeault wrote:Ick....I just name them whatever makes sense.


+1
Having an name which immediately tells you something about the class is always helpful.

Well, names like IBladeTrans and IScrewTrans are useful in that respect - they immediately tell you that they are interfaces.

(Assuming you care.)

That seems to be antithetical to what Bear was saying. He doesn't want to worry about whether a given class or interface is a class, or abstact class, or interface. Most of the time at least. Not as part of the name. (And I agree with Bear on this point.)

So, Maneesh, when you say "+1", are you agreeing with Bear? (And me?) Or do you disagree? So far, I really can't tell.

Rob, when you say "+2", same question.


on the lighter side :

how about IScrewedThis or LoveYou implements ILoveYou
The whole "I" thing sounds like iPod or iPhone

No offense to anyone please
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:That seems to be antithetical to what Bear was saying. He doesn't want to worry about whether a given class or interface is a class, or abstact class, or interface. Most of the time at least. Not as part of the name. (And I agree with Bear on this point.)

So, Maneesh, when you say "+1", are you agreeing with Bear? (And me?) Or do you disagree? So far, I really can't tell.

Rob, when you say "+2", same question.

I agree with Bear, Maneesh and you that in general the name should not indicate what a class is. The only exception for me is the Abstract<Interface> names that are used for basic implementations of interfaces; abstract classes that can be used to help implement an interface, and have no other purpose. AbstractTableModel, AbstractCollection, AbstractList, AbstractMap, etc are examples of those. You can do without them, you just have to do all the hard work yourself.

The root of hierarchies should not have Abstract in the name. Calendar, Component, ClassLoader, Number are all examples of these. If Sun would decide that Calendar could become a basic calendar and no longer needed to be abstract all they would need to do is remove the abstract modifier and implement the abstract methods. No code would be broken, and the name would still be valid.
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this statement :
seetharaman venkatasamy wrote:
I prefere this. PrintableFile is a Class which implements IPrintableFile Interface . is it make sense ?


contradicts this statement
seetharaman venkatasamy wrote:
Never do this [dont restrict the parameter type to a specific implementation].


for the example i provided
------------------------------------------------------------------------------------------------

In case of any misunderstandings:
I prefer public void printFile(PrintableFile file) where PrintableFile is an interface
over public void printFile(IPrintableFile file) or public void printFile(PrintableFileInterface file)

An IMHO,
An interface does not restrict the parameter type to a specific implementation, a class does.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@salvin : You are getting me wrong Completely .
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:In case of any misunderstandings:
I prefer public void printFile(PrintableFile file) where PrintableFile is an interface


Hmm.. i thought of PrintableFile is a Class
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your insights...

Fortunately, eclipse has the Refactor and Rename option. It made the whole work easy...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic