Re: What scope is best for defining Enum type?
- From: "Beth Massi [Architect MVP]" <bmassi@xxxxxxxxxxx>
- Date: Fri, 15 Apr 2005 14:36:59 -0700
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 ***
.
- References:
- What scope is best for defining Enum type?
- From: Alex Feldman
- What scope is best for defining Enum type?
- Prev by Date: Login to SQL server
- Next by Date: StringBuilder size question?
- Previous by thread: What scope is best for defining Enum type?
- Next by thread: Re: What scope is best for defining Enum type?
- Index(es):
Relevant Pages
|