Jelle Druyts .NET Consultant
Just another ignorant weirdo from Antwerp, Belgium trying to make sense out of it all
Back when I was preparing my "Best Practices In Framework Design" talk for the Developer & IT Pro Days in February, I got the following question during my dry run: “Why do you need to suffix exceptions (e.g. ArgumentException) and attributes (e.g. ObsoleteAttribute) but not enums (e.g. Color, not ColorEnum)?”.
ArgumentException
ObsoleteAttribute
Color
ColorEnum
I didn’t really have an answer other than "because Microsoft said so" at that time, but I just discovered the reason behind it while re-reading the excellent Framework Design Guidelines book. It’s the following guideline that makes the difference:
Consider ending the name of derived classes with the name of the base class.
So you should suffix exceptions and attributes, simply because they inherit from the System.Exception and System.Attribute base classes:
System.Exception
System.Attribute
public class ArgumentException : Exception { ... } public class ObsoleteAttribute : Attribute { ... }
Enums - and delegates as well for that matter - should not be suffixed because they don’t (explicitly) inherit from an enum or delegate base class:
public enum Color { ... } public delegate void ClickEventHandler(...)
Behind the scenes, the compiler will make an enum a subclass of System.Enum and a delegate of System.MulticastDelegate, but you don’t explicitly state this in most languages and in fact you can’t build inheritance hierarchies with these types. So they don’t need to follow the guideline.
System.Enum
System.MulticastDelegate
Maybe it doesn't really matter that much to you, but I thought it was a nice piece of background information on the "why" anyway