• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

interface naming convention

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From K & B i've read Interfaces shud typically be adjectives like serializable, Runnable etc...
Then what abt interfaces like Vector, Map,List are they adjectives?
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmmm...
adjective shows quality so it is used as name for interface,
adjective(interface) qualifies noun(class),
but what about interface that qualifies another interface ?
why Map is not called KeyValueHolder(may be too long)
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say that the idea of using adjectives for interfaces is a recommendation which was followed very often in the beginning days of Java, but has become increasingly ignored over time, even by Sun itself. There is no absolute rule here.

I would say that if you're naming a new interface, it's worth at least considering a name that's an adjective - but often these don't really make sense. If Map and List were Mappable and Listable instead - well aside from being longer, those actually don't make sense to me. The word "Mappable" to me would apply to the thing that's being mapped, not to the map itself. The North American continent is mappable, but the pictures of it in my atlas are maps, not mappables. Applying this (loosely) to the collections framework, I would think that a Mappable is some external concept or reality that you're trying to map, whereas a Map is the object that contains the information about the mapping. So Map makes more sense to me than Mappable does.

More generally, I think that both interface names and class names represent types of objects, and as such it usually makes more sense to me to use nouns for objects. Often when I see a class/interface name, I don't immediately care whether it's a class or interface. That's minor. I want to know what its purpose is. Choosing a good name that communicates that purpose is more important than identifying whether you're talking about a class or interface, in my opinion, and that's why many modern interface names don't bother with the latter.

For purposes of the SCJP, I think you should know that interfaces are often named as adjectives, but this is by no means an absolute rule. If you see a capitalized name that ends in -able, it's a pretty good bet that it's an interface. But if you see a capitalized name that doesn't end in -able, you really have no way of knowing whether it's a class or interface. Unless of course you proceed to look at the rest of the API or source code.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy ranchers,

I know also of one class that is named like an interface:
java.lang.Throwable


Bu.
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim,

The reasoning makes good sense to me.


Thanks,
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic