Interface Naming – Prefix ‘Can-‘ vs Suffix ‘-Able’

apiinterfaces

It's common to use '-able' as a suffix for interfaces e.g.

Serializable
Printable
Enumerable
Drinkable
Shootable
Rotatable

I was thinking that 'Can-' might better because it may be more descriptive. Yes, it is more wordy and it adds noise to the interface name. In particular, passive verbs can be used.

E.g. 1 does Shootable mean that the object is able to shoot (a gun might implement this), or does it means that it can be shot at (a target board might implement this). With the 'Can-' prefix, the former would be "CanShoot" and the latter would be "CanBeShotAt" or "CanShootAt".

E.g. 2 A document 'CanBePrinted' and a printer 'CanPrint'

Or, should we stick with '-Able' and let the documentation provide the context?

Any opinions.

Best Answer

Perhaps you want Is-able?

Some examples from .Net:

NetworkStream.Readable
NetworkStream.Writable
Stream.CanRead
Stream.CanWrite
Type.IsSerializable

There doesn't appear to be a uniform standard. Go with what reads well.

if (document.IsPrintable && printer.CanPrint) { printer.Print(document) }

EDIT: As pointed out, the question was about Interfaces, not Properties.

In that case, I can't find any interfaces named Can-. Interfaces tend to always use -able. I'd agree with this terminology. A method may request as a parameter a ISerializable object or IPrintable document. Asking for a ICanBeSerialized object or a ICanBePrinted document is very awkward to read.

On the other side, the Printer, I'd suggest simply calling the interface IPrinter. Your method will be asking for a IPrinter device.

Read the method signature below out loud. (Personally, I consider the "I" prefix to be silent.) Does it read well? Does it sound right?

void PrintDocument(IPrinter device, IPrintable document)
{
    device.Print(document)
}
Related Topic