Tuesday, 24 April 2018

Naming Conventions for Abstract Classes in C#

Unlike with interfaces which tend to begin with a capital I, abstract classes have no such convention in C#.

(A famous example of prefix I usage "in the field" is the ubiquitous IEnumerable in System.Collections).

Some possible conventions that can be used (though some people oppose any prefix or suffix) -
  • Prefix : Abstract
  • Suffix:  Base
On a side note, there are some facts about abstract classes in C#.

Abstract classes cannot be sealed and they cannot be private, for obvious reasons. Abstract members cannot be labelled virtual as they are implicitly virtual. Also an abstract member cannot be static - perhaps less obvious.

No comments: