473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A class with only static members

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
Nov 15 '05 #1
1 1015
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
-----Original Message-----
Hi everyone,

I have a class that I want to use to store application state information. Iwas thinking that I would probably want to make all the information staticin that class because the application should only have one copy ofapplication information.

First Question:
Is this the right sort of scenario to use a static class? Or should I makean 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 instantiatingan object, I can't do that.
So I'm not sure how to initialise the class. The actual class is calledStateManager. 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
.

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
6
by: lovecreatesbeauty | last post by:
Hello Experts, Why static data members can be declared as the type of class which it belongs to? Inside a class, non-static data members such as pointers and references can be declared as...
5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
8
by: crjjrc | last post by:
Hi, I've got a base class and some derived classes that look something like this: class Base { public: int getType() { return type; } private: static const int type = 0; };
3
by: puzzlecracker | last post by:
Would you quickly remind me the difference between, regular class, static class, and nested class? Thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.