Type Name Suffixes#

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)?”.

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:

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.

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 :-)

Comments are closed.
All content © 2012, Jelle Druyts
On this page

Recent Photos
www.flickr.com
This is a Flickr badge showing public photos from Jelle Druyts. Make your own badge here.
Advertising
Top Picks
Statistics
Total Posts: 350
This Year: 0
This Month: 0
This Week: 0
Comments: 530
Archives
Sitemap
Disclaimer
This is my personal website, not my boss', not my mother's, and certainly not the pope's. My personal opinions may be irrelevant, inaccurate, boring or even plain wrong, I'm sorry if that makes you feel uncomfortable. But then again, you don't have to read them, I just hope you'll find something interesting here now and then. I'll certainly do my best. But if you don't like it, go read the pope's blog. I'm sure it's fascinating.

Powered by:
newtelligence dasBlog 2.0.7226.0

Sign In