Interface and Class Naming Conventions

Home - About » Computer Science - Programming - Conventions
Computer Science
Research, Industry Work,
Programming
Community Service
Hillside Group, CHOOSE,
Stanford GSA
The Serious Side
Business School,
Learning Chinese
Humorous Takes
Switzerland, United States,
Software, Fun Photos
Travel Stories
Europe, United States, Asia
  
Living Places
Berlin (+ Gallery), Zürich
Boston, S.F. + Bay Area

Consider the example of an interface for name objects, an abstract superclass that partially implements the interface, and some subclasses of the abstract superclass that implement the missing holes inherited from the superclass.

Primary convention

The convention goes like this:

  • Interface. No prefix, just the primary name, for example, "Name".
  • Abstract class. Gets prefixed with "Abstract", for example "AbstractName".
  • Concrete class. Just give them a telling name, for example, "StringName" or "VectorName".
  • Default implementation class. Gets prefixed with "Default", "Standard", or "Simple".

Before we decided to use this convention, we had tried both of the following variants. They are still justified in special circumstances.

Backup convention: prefixing interfaces

The convention goes like this:

  • Interface. Gets prefixed with "I", for example, "IName".
  • Abstract class. Gets prefixed with "Abstract", for example "AbstractName".
  • Concrete class. Just give them a telling name, for example, "StringName" or "VectorName".
  • Default implementation class. Gets prefixed with "Default", "Standard", or "Simple".

This one reads natural and can be used if you insist on making interfaces easily recognizable by their name.

Backup convention: postfixing implementations

The convention goes like this:

  • Interface. No prefix at all, just the regular name, for example, "Name".
  • Abstract class. Gets postfixed with "DefImpl", for example, "NameDefImpl".
  • Concrete class. Gets postfixed with "Impl", for example, "StringNameImpl" or "VectorNameImpl".
  • Default implementation class. Gets prefixed with "Default", etc. and postfixed with Impl.

This one is typically used if you need an interface for every class, for example, in a distributed system. In the Geo system, we generated proxies and adapters on the fly and thus required interfaces. San Francisco of IBM does a similar thing.

Copyright (©) 2007 Dirk Riehle. Some rights reserved. (Creative Commons License BY-NC-SA.) Original Web Location: http://www.riehle.org