Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > enum or static class

Reply
Thread Tools

enum or static class

 
 
mavrick_101
Guest
Posts: n/a
 
      06-16-2009
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
 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      06-17-2009
=?Utf-8?B?bWF2cmlja18xMDE=?= <(E-Mail Removed)>
wrote in news:(E-Mail Removed):

> 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! |
*******************************************
 
Reply With Quote
 
 
 
 
Abubakar
Guest
Posts: n/a
 
      06-18-2009
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
Abubakar
Guest
Posts: n/a
 
      06-18-2009
> 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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

>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"enum" vs. "enum class" Ansel C++ 16 08-27-2012 10:34 AM
Difference between enum class and enum struct Brian C++ 4 02-27-2010 04:03 PM
enum: display elements of an enum specified at runtime Jerminia Java 3 10-07-2005 10:08 PM
enum within an enum - Java 6 06-13-2005 12:51 AM
How is "static const int" better than "static enum"? Ajax Chelsea C++ 3 12-05-2003 12:37 AM



Advertisments