0

Need brief answers on Java interface naming pattern.

Why most JAVA Interfaces name suffix has "able" ?

For e.g

java.io.Serializable

java.lang.Cloneable

java.lang.Comparable

java.lang.Runnable

I have explored and read that its because to identify the behavior, actions and capabilities etc. But doesn't get it exactly. Can anyone help with some useful example scenario.

Best!

Arun

Arun Kumar
  • 6,534
  • 13
  • 40
  • 67
  • 2
    related: http://stackoverflow.com/questions/17605896/java-naming-convention-for-can-do-interface-as-opposed-to-can-be-done-to?rq=1 – Thilo May 27 '14 at 10:24
  • I wouldn't say most interfaces end "able". Just the ones that allow the class to be `something`ed. Plenty end "or" or "er" when they are for classes that `something` something else. This is more an english language question than a programing specific question – Richard Tingle May 27 '14 at 13:12

3 Answers3

2

These *able interfaces define operations that we can do on instances of that class.

For example, a class that implements java.lang.Comparable indicates that instances of that class can be compared with one another. Similarly, a class that implements java.lang.Runnable indicates that instances of that class can be ran by java.lang.Thread.

fajarkoe
  • 1,543
  • 10
  • 12
0

Because classes implemented that interface are 'able' to do that specific thing. Eg. Objects of the Class implementing Serializable are 'able' to serialize. And rest of the examples follow same.

codingenious
  • 8,385
  • 12
  • 60
  • 90
0

Inheritance follows IS-A relationship. The interfaces are used as top parent for an object which would be worked on in a method.

e.g. let us assume that we want to write a method, which accepts any object which can be cloned, and reject all other objects.

public void doSomethingWithClonableObjects(Clonable c){
  ...
}

Ending such interfaces with able, makes a flow in english and hence improved understanding. i.e, this method would work for all objects which are clonable.

or, If an object IS clonable, it would be accepted.

For any object implementing Clonable interface, we can definitely say that this object IS Clonable.

Mohit Kanwar
  • 2,962
  • 7
  • 39
  • 59
  • `Inheritance follows IS-A relationship` , but what about HAS-A ?? Does a interface not followed in HAs-A relation? – Arun Kumar May 29 '14 at 04:55