
Signature
Every thing is perfect, as long as you share!!!
Don''t forget to rate the post
> First thing first, pl undestand that enums are by definition as enumerations
> by EnumBuilder whos elements have correct type.
EnumBuilder? He is just asking if there is a way to make an enum value-
safe. He doesn't want to have people passing in integers instead of
predefined values.
> Secondly, if you have to induce special functionality to enums, you can
> achieve them as said by Jon Skeet. Take a class which is a type of enum and
> then carry on to implement the functionality.
If you are going to reference something, provide a means of looking
into it, like a link.
Here you go:
http://msmvps.com/blogs/jon.skeet/archive/2006/01/05/classenum.aspx
This should help you out.
> Finally, apart of the above, i always recommend to write your won custom
> class to spit your requirement. So that you know how you have tailored your
> class, instead of depending on the BCL. For more explanation and help, post
> back your requirement in detail.
Finally, not everyone knows what BCL (Base Class Library) stands for.
His post was detailed enough, you seem to have understood him fine;
you are just being anal.
Long ago, there was a wise man who said that the best way to make a
type-safe enum was to make a new class for each enum value and have a
polymorphic method that performed what the enum was meant to
distinguish. I was part of a large enum discussion (this question
comes up a lot) for C++. Most people would recommend the State Pattern
or making your enums polymorphic classes. Personally, I think there is
a point where being "too careful" is really just a waste of time.
Trying to prevent illegal values is like admitting that you or your
coworkers can't play by the rules and that your language isn't type-
safe. In other words, if you all promise not to pass integers where
enums belong, you'll be fine. I mean, the BCL uses enums all over and
they will often overlook illegal values (unless they throw an
exception due to bad state).
I hope you are still tracking this post. Thanks.