|
-
July 12th, 2006, 06:42 AM
#2
Re: design issue with static vars
I'm not sure if I understood you well, but it seems to me that you are surprised that after creating the second instance of ClassWithStatic, you lost the loaded data. It is because you write this code this way - you initialize your statics in instance constructor, which is called everytime an instance is created.
One solution is to initialize ClassWithStatic in "class" constructor
Code:
static ClassWithStatic()
{
if (_xmlDoc == null)
{
Init();
}
}
But dealing with static variables is more complicated than neccessary. Look at singleton desing pattern at http://www.dofactory.com/Patterns/PatternSingleton.aspx
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|