File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Naming Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Naming Interfaces" Watch "Naming Interfaces" New topic
Author

Naming Interfaces

Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
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?


Sean Clark ---> I love this place!!!
Me ------> I definitely love this place!!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61588
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

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

My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10515
    
    9

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

@Maneesh, ye "ick" kya hota hai ??
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

Bear Bibeault wrote:Ick.
...

What does 'ick' mean Bear ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61588
    
  67

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
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

hmm, and i went crazy searching for that acronym
so, I guess its a slang form of "yuck"
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19755
    
  20

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
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

Joined: Mar 05, 2008
Posts: 3018
    
  10
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

Joined: Jul 26, 2007
Posts: 10515
    
    9

I agree on not liking the I... convention. I also agree about having sensible names.
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jan 28, 2008
Posts: 5575

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
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

I would really really prefer to allow an interface there rather than a class.
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

btw what i did was a classic example of Using an Interface as a Type
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

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

Joined: Oct 27, 2005
Posts: 19755
    
  20

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
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

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

Joined: Jan 28, 2008
Posts: 5575

@salvin : You are getting me wrong Completely .
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Thanks for all your insights...

Fortunately, eclipse has the Refactor and Rename option. It made the whole work easy...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Naming Interfaces