enum or static class

Discussion in 'ASP .Net' started by mavrick_101, Jun 16, 2009.

  1. mavrick_101

    mavrick_101 Guest

    Hi,

    I have some constants that I would be using to specify some properties.

    I found it hard to use enums for this purpose and feel more comfortable
    using a static class that would have static properties returning the
    constants.

    What is THE RIGHT WAY to do it?

    Thnx
     
    mavrick_101, Jun 16, 2009
    #1
    1. Advertising

  2. =?Utf-8?B?bWF2cmlja18xMDE=?= <>
    wrote in news::

    > Hi,
    >
    > I have some constants that I would be using to specify some
    > properties.
    >
    > I found it hard to use enums for this purpose and feel more
    > comfortable using a static class that would have static properties
    > returning the constants.
    >
    > What is THE RIGHT WAY to do it?
    >
    > Thnx
    >


    Right way? It depends.


    If you are talking a "property bag" type setup, having a static class,
    or perhaps a singleton, works nicely. If they are different for each
    user, you can use session, or at least cache by session id, etc.

    If they are truly constants for the app, spinning up a singleton for the
    application settings is very nice, as it is quite clean. You can then
    deploy more as needed, with application deployment of course.

    You can also have your singleton derive from a dictionary, or similar,
    and spin it up from config files or database at startup.

    The point? The correct answer depends on the use and scope of the items.


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
     
    Gregory A. Beamer, Jun 17, 2009
    #2
    1. Advertising

  3. mavrick_101

    Abubakar Guest

    Look at System.Drawing.Color for example. They chose to make it "public
    struct Color" and overloaded its != and == operators, and added few methods
    like FromKnownColor or GetBrightness (instance methods), and all the colors
    are declared as "public static Color" followed by color name. Here the
    colors are something that could have been enums, but the developer wanted
    some functionality to be associated with that data structure also so he
    chose a class with a lot of static data. I think that if the overloading of
    operators and public instance methods were not at all required by the
    developer there, he would have made it into an enum.

    Just my thoughts about "enum" vs "class with static members".

    ...ab


    "mavrick_101" <> wrote in message
    news:...
    > Hi,
    >
    > I have some constants that I would be using to specify some properties.
    >
    > I found it hard to use enums for this purpose and feel more comfortable
    > using a static class that would have static properties returning the
    > constants.
    >
    > What is THE RIGHT WAY to do it?
    >
    > Thnx
     
    Abubakar, Jun 18, 2009
    #3
  4. mavrick_101

    Abubakar Guest

    > chose a class with a lot of static data. I think that if the overloading
    > of

    I meant struct, but class can also be used

    > Just my thoughts about "enum" vs "class with static members".

    class/struct ..

    Now bcuz of my misused words up there I hope you dont get confused about
    classes vs structs :). But before asking here just google a bit and u'll
    find a lot of clear n easy to understand info. Just in case.

    "Abubakar" <> wrote in message
    news:...
    > Look at System.Drawing.Color for example. They chose to make it "public
    > struct Color" and overloaded its != and == operators, and added few
    > methods like FromKnownColor or GetBrightness (instance methods), and all
    > the colors are declared as "public static Color" followed by color name.
    > Here the colors are something that could have been enums, but the
    > developer wanted some functionality to be associated with that data
    > structure also so he chose a class with a lot of static data. I think that
    > if the overloading of operators and public instance methods were not at
    > all required by the developer there, he would have made it into an enum.
    >
    > Just my thoughts about "enum" vs "class with static members".
    >
    > ..ab
    >
    >
    > "mavrick_101" <> wrote in message
    > news:...
    >> Hi,
    >>
    >> I have some constants that I would be using to specify some properties.
    >>
    >> I found it hard to use enums for this purpose and feel more comfortable
    >> using a static class that would have static properties returning the
    >> constants.
    >>
    >> What is THE RIGHT WAY to do it?
    >>
    >> Thnx

    >
     
    Abubakar, Jun 18, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    591
  2. Jerminia
    Replies:
    3
    Views:
    659
    Roedy Green
    Oct 7, 2005
  3. Ajax Chelsea
    Replies:
    3
    Views:
    17,006
    Ajax Chelsea
    Dec 5, 2003
  4. Brian
    Replies:
    4
    Views:
    2,770
    Brian
    Feb 27, 2010
  5. Ansel

    "enum" vs. "enum class"

    Ansel, Aug 26, 2012, in forum: C++
    Replies:
    16
    Views:
    788
    Ansel
    Aug 27, 2012
Loading...

Share This Page