A class with only static members

  • Thread starter Thread starter Simon Harvey
  • Start date Start date
S

Simon Harvey

Hi everyone,

I have a class that I want to use to store application state information. I
was thinking that I would probably want to make all the information static
in that class because the application should only have one copy of
application information.

First Question:
Is this the right sort of scenario to use a static class? Or should I make
an object and use a Singleton pattern? Would there be an advantage to that?

My second question is how to initialise this static state class.

Normally I would just use the new operator and call the objects contructor,
passing in any appropriate data. However, given that I'm not instantiating
an object, I can't do that.
So I'm not sure how to initialise the class. The actual class is called
StateManager. What I need to be able to do is something like:

StateManager.static_constructor(state_data);

I'm not sure how to achieve that effect though.

Thanks everyone

Take care

Simon
 
Does not matter if you want to use static or singleton as
long as you are consitent with what you use.

You will not be able to invoke a static constructor the
way you wanted. You can have a regular constructor for
the class though. Or you can have static initializer.

public class YourClass
{
static YourClass()
{
// Put your init code here.
}
}

Tu-Thach
 
Back
Top