Moving Beyond Enumerations
page 5 of 5
by Steven Smith
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 30359/ 63


In many cases, enumerations are a good fit for the needs of a system.  However, if and when the concept being modeled by the enum gains any kind of behavior beyond its numeric constant and developer-friendly label, it may be time to consider moving from an enum to a class.  In this article, you've seen how you can easily make this transition with minimal changes in your code that already makes use of an enum, provided that you keep the same naming convention for your class and its named static instances.

Learn more about software development best practices in my Principles of Object Oriented Design course available from PluralSight.

You can follow me on my blog at and on Twitter at  You can download the (very small) sample code for this article.

View Entire Article

User Comments

Title: Good Catch   
Name: Steve Smith
Date: 2011-08-30 7:56:15 PM
Good catch. Yes, those fields should be readonly, of course.

Title: public static roles should be readonly   
Name: Ian Mercer
Date: 2011-08-30 5:01:05 PM
Totally agree that enums should be replaced with classes as soon as they stop being enums. One improvement to your class would be to make all the values readonly, e.g.

public static readonly Author ...

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-05-27 7:42:57 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search