Re: What scope is best for defining Enum type?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



As a rule of thumb, I usually only declare Enums inside of classes when they
are only relevant to the class itself (and make them Private), otherwise I
place them in the appropriate Namespace.

"Alex Feldman" <alex-feldman@xxxxxxxxxxx> wrote in message
news:OpRwhsfQFHA.3628@xxxxxxxxxxxxxxxxxxxxxxx
> Which of the following is better? Defining an enum type inside a class
> as a nested type, or in the the namespace?
> An example of nested type enumerated type would be:
>
> public Class Product
> Public Enum Status
> psNormal
> psCharged
> End Enum
>
> .....'other stuff in class
> 'Use the enumerated type within the class like this:
> Dim enuPS as Status
> End Class
>
> So in the rest of the class I would have to declare a new instance of
> the enumerated type as such:
> Dim enuPS as Product.Status
>
> The regular approach (defining in the namespace would) would be as such:
>
> public class Product
> .....
> end class
>
> Public Enum ProductStatus
> psNormal
> psCharged
> End Enum
>
> Notice that the name of the enumerator would change depending depending
> whether it's nested to the object or not.
>
> The framework engineers clearly seem to think that the namespace
> definition of enumerators is better, but I still care about the
> community opinion. I think there are pros and cons to both approaches.
> The biggest advantage that i see of nesting the enum definition is that
> it's tightly coupled with a class that it makes most sense with. On the
> con side you have to use the . which makes it look like a member of a
> class instead of a type definition, and the autocompletion in the IDE
> won't work when declaring new instances of the type.
>
> So what does everyone think about that? Which way is better?
>
> Thanks.
>
> Alex
>
> *** Sent via Developersdex http://www.developersdex.com ***


.



Relevant Pages

  • Re: What scope is best for defining Enum type?
    ... > public Class Product ... > Public Enum Status ... > 'Use the enumerated type within the class like this: ... Did you mean to type "in the rest of the namespace"? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Enumerated types
    ... Enum ACGroup ... I cannot then access the members of the group. ... One alternative I could try, in the mean time, is to declare a string array ...
    (microsoft.public.access.formscoding)
  • Re: non-static method gotcha
    ... the declared enum, 'SubmissionSite' in your example. ... Its effect is to declare that C is not an inner class. ... extends the immediately enclosing enum type. ... decompiled anonymous class. ...
    (comp.lang.java.help)
  • Re: Newbie Question
    ... It may be a problem but the compiler error clearly stated that he tried to ... declare a method where only a class, delegate, enum, interface, or struct is ... >> public static extern int SendCharFmtMsg(IntPtr hWnd, int Msg, int ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: stratgies for organizing elements in a passed array
    ... enumeration is nothing except a special syntax to declare a set of named ... You don't need f2003 to declare a set of named constants. ... to have symbolic names for the various keywords. ... I use an old preprocessor to get the equivalent of an enum. ...
    (comp.lang.fortran)