Static Variables.  
Author Message
Chocreaper





PostPosted: Fri Nov 30 00:33:46 PST 2007 Top

Visual C#.Net >> 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.

DotNet144  
 
 
Roman





PostPosted: Fri Nov 30 00:33:46 PST 2007 Top

Visual C#.Net >> Static Variables. 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();
}
}



 
 
James





PostPosted: Fri Nov 30 02:35:31 PST 2007 Top

Visual C#.Net >> Static Variables. Hi,

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

James

"Gobinath" <EMail@HideDomain.com> wrote in message
news:%EMail@HideDomain.com...
> 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.
>