473,386 Members | 1,745 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,386 software developers and data experts.

Static Variables.

Hi,

I have a pretty basic question.

I have a C# control with lots of classes and I need few instances(manager
classes) shared by all the classes in the conrol. So I define a Static Class
and it works OK.

Now When I want multiple instances of the control in the same application
and each instance to have it own set of manager instances, how do I do it?
Static is shared between the two instance of the control, which I want to
avoid.

Is there a specific variable type or a standard design pattern for it?

Thanks & Regards,
Gobi.
Nov 30 '07 #1
2 1111
I asume that you add instances of your control with the designer.
Try something linke that.

ClassThatUseMyControl {

...
public ClassThatUseMyControl() {
InitializeComponent();
_MyClassInstance1.Controller =
MyClassControllerFactory.GetController();
_MyClassInstance2.Controller =
MyClassControllerFactory.GetController();
}
}

public class MyControl : Control {

...

public IMyController {
get { return _myController; }
set { _myController = value; }
}
}

public interface IMyController {
//extract interface from the current implementation of your
controller
}

public static class MyControllerFactory {

private class MyPrivateController : IMyController {
//your controller code
}

public IMyController GetController() {
return new MyPrivateController();
}
}

Nov 30 '07 #2
Hi,

I think your best bet will be to "promote" your static manager class to an
instance variable on the control.

James

"Gobinath" <go********@coolgoose.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi,

I have a pretty basic question.

I have a C# control with lots of classes and I need few instances(manager
classes) shared by all the classes in the conrol. So I define a Static
Class and it works OK.

Now When I want multiple instances of the control in the same application
and each instance to have it own set of manager instances, how do I do it?
Static is shared between the two instance of the control, which I want to
avoid.

Is there a specific variable type or a standard design pattern for it?

Thanks & Regards,
Gobi.
Nov 30 '07 #3

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

Similar topics

1
by: James | last post by:
Hello Java NG, I not sure if this is the right NG for this type of question but if not please let me know which is, TIA Any way first off let me say I'm a student and this WAS last weeks lab,...
9
by: Bryan Parkoff | last post by:
I have noticed that C programmers put static keyword beside global variable and global functions in C source codes. I believe that it is not necessary and it is not the practice in C++. Static...
28
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. ...
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.