Home All Groups Group Topic Archive Search About
Author
16 Jun 2009 7:09 PM
mavrick_101
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

Author
17 Jun 2009 5:49 PM
Gregory A. Beamer
=?Utf-8?B?bWF2cmlja18xMDE=?= <mavrick***@discussions.microsoft.com>
Show quoteHide quote
wrote in news:02C63C14-159C-41A8-89CB-C352B117B6B7@microsoft.com:

> 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

*******************************************
Show quoteHide quote
|      Think outside the box!             |
*******************************************
Are all your drivers up to date? click for free checkup

Author
18 Jun 2009 12:18 AM
Abubakar
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


Show quoteHide quote
"mavrick_101" <mavrick***@discussions.microsoft.com> wrote in message
news:02C63C14-159C-41A8-89CB-C352B117B6B7@microsoft.com...
> 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
Author
18 Jun 2009 12:29 AM
Abubakar
> 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.

Show quoteHide quote
"Abubakar" <noem***@nowhere.com> wrote in message
news:OMi8hp67JHA.5476@TK2MSFTNGP05.phx.gbl...
> 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" <mavrick***@discussions.microsoft.com> wrote in message
> news:02C63C14-159C-41A8-89CB-C352B117B6B7@microsoft.com...
>> 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
>

Bookmark and Share