Arun Kumar
Arun Kumar

Reputation: 6794

JAVA : Interface naming practices and guidelines

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

Upvotes: 0

Views: 788

Answers (3)

Mohit Kanwar
Mohit Kanwar

Reputation: 3050

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.

Upvotes: 0

fajarkoe
fajarkoe

Reputation: 1563

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.

Upvotes: 2

codingenious
codingenious

Reputation: 8653

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.

Upvotes: 0

Related Questions