Interfaces Should Be Nouns

From InterfacesShouldBeAdjectives ...

Interfaces Should Be Nouns

The primary reason to create an interface is to allow for a collection of similar, but different objects. As a concrete example, if one wanted a collection of Small Dogs, Medium Dogs, and Large Dogs; the obvious interface to create would be Dog. The adjectives Small, Medium, and Large would be applied when creating the concrete classes SmallDog, MediumDog, and LargeDog.

An interface is a generalization of a set of classes. The interface should be a noun. The derived classes can then be named using Adjective+Noun (such as SmallDog from Dog) or using a more specific noun (such as Dog From Animal).

The use of an adjective for an interface may be appropriate in some situations, such as a decorator pattern. It is possible one may want a Small wrapper that could take a Dog, Cat, or Fish, but this type of use is much more the exception than the rule. Use a noun to name an interface as a general rule and only use other naming conventions where an exception is justified.

Perhaps interfaces should be interfaces ...

{Discussions in ThereAreNoTypes, AttributesInNameSmell, and PrimaryNoun may take issue with this.}


CategoryInterface


EditText of this page (last edited November 20, 2004) or FindPage with title or text search