Kvass
Kvass

Reputation: 8444

Java - naming convention for can-do interface as opposed to can-be-done-to

In Java more often than not I have come across interfaces with the suffix -able, e.g. serializable, iterable, etc. This suggests that the object that implements these interfaces has qualities such that certain actions can be done to it, e.g. the object can be serialized or can be iterated over. What if I want to implement an interface that suggests that certain actions can be done by the object rather than to the object.

For example, it makes sense for a human to implement an interface along the lines of CanDrive but does not make sense for a human to implement the interface Drivable, as a human cannot be driven. A car, conversely, should implement Drivable but certainly should not implement CanDrive because no car should ever drive itself.

The name CanDrive sounds remarkable ugly to me as an interface name. Is there a suffix convention for naming an interface that suggests this kind of can-do relationship (as opposed to can-be-done-to)?

Upvotes: 1

Views: 165

Answers (3)

Bohemian
Bohemian

Reputation: 425348

End the name in -or or -er (depending on English spelling).

There are lots of examples even in the JDK of interfaces that do things:

  • Executor
  • Conparator
  • DocumentHelper
  • Tokenizer

Etc.

And in your example of CanDrive, you would use Driver.

Upvotes: 0

Erik Nguyen
Erik Nguyen

Reputation: 879

I don't think there is much of a naming convention. For instance the done to iterable interface is related to the can-be-done-by iterator interface. Comparable to Comparator etc. It seems to me that if there is such a naming "convention" you'd use -or instead of -able.

Upvotes: 1

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727047

It is common to use agent nouns or noun phrases for classes and interfaces that do things to other objects:

Serializer
ClassLoader

Upvotes: 1

Related Questions