Application Values

S

shapper

Hello,

I am working on a project and there are a few values that are used in
many classes.

For example:
DataPath
GoogleAnalyticsAccount
ContactEmail
GatewayEmail
etc

Should I create a static class with some "global variables" (I think
static) and access them from the other classes?

Thanks,
Miguel
 
J

Jesse Houwing

Hello shapper,
Hello,

I am working on a project and there are a few values that are used in
many classes.

For example:
DataPath
GoogleAnalyticsAccount
ContactEmail
GatewayEmail
etc
Should I create a static class with some "global variables" (I think
static) and access them from the other classes?

Thanks,
Miguel

These can typically be stored in a Settings object. Go to the Settings tab
of your project and you'll find what you're looking for.
 
P

Peter Duniho

Hello,

I am working on a project and there are a few values that are used in
many classes.

For example:
DataPath
GoogleAnalyticsAccount
ContactEmail
GatewayEmail
etc

Should I create a static class with some "global variables" (I think
static) and access them from the other classes?

It depends on the nature of the values. Even if they're all constant,
that doesn't necessarily mean they belong in the same class.

As Jesse suggests, it's possible you might want them to be in your
Settings object. Or maybe you don't. Based entirely on the names (which
is all you've told us), Settings seems like it would well. But with such
a vague question, it's difficult to say for sure. Maybe they are
constants that individually are specific to different classes in your
project, or maybe they are configurable values that need some per-class
qualification. Only you know for sure.

Pete
 
S

shapper

It depends on the nature of the values.  Even if they're all constant,  
that doesn't necessarily mean they belong in the same class.

As Jesse suggests, it's possible you might want them to be in your  
Settings object.  Or maybe you don't.  Based entirely on the names (which  
is all you've told us), Settings seems like it would well.  But with such  
a vague question, it's difficult to say for sure.  Maybe they are  
constants that individually are specific to different classes in your  
project, or maybe they are configurable values that need some per-class  
qualification.  Only you know for sure.

Pete

Thank you for the suggestions. I will try to figure the best way.
I am not sure yet ... I also have Web.Config and just a normal class.
I am trying to organize my ideas.

Thanks,
Miguel
 
I

Ignacio Machin ( .NET/ C# MVP )

Thank you for the suggestions. I will try to figure the best way.
I am not sure yet ... I also have Web.Config and just a normal class.
I am trying to organize my ideas.

Thanks,
Miguel

Hi,

You should not access the config file in all over your program. You
can have a static class that is who access the AppSettings[] part of
the config file, this allow you to encapsulate all the config logic in
one class.
 
I

Ignacio Machin ( .NET/ C# MVP )

Hello shapper,







These can typically be stored in a Settings object. Go to the Settings tab
of your project and you'll find what you're looking for.

For a mid-sized application I prefer to create a class that wrap the
Setting object. The thing is that it's most probably there will be
settings that are calculated using a static class you isolate this
differences.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top