Software Design Question

  • Thread starter Thread starter babylon
  • Start date Start date
B

babylon

is it normal to do something like:

public MYCLASS
{
private static MYCLASS defaultInstance = null;
public static MYCLASS GetDefaultInstance()
{
return MYCLASS.defaultInstance;
}
public MYCLASS(int arg1, string arg2)
{
// Init...
...
MYCLASS.defaultInstance = this;
}
}

as all other component can get a reference to MYCLASS easily
(MYCLASS.getDefaultClass())

if I don't do it this way
I need to pass a reference of MyClass to the component that will use it....

or there are better solution available in C# that is better than the above
solution?
 
as all other component can get a reference to MYCLASS easily
(MYCLASS.getDefaultClass())

if I don't do it this way
I need to pass a reference of MyClass to the component that will use it....

or there are better solution available in C# that is better than the above
solution?

It looks like you're attempting a singleton object
(http://www.yoda.arachsys.com/csharp/singleton.html). If that's not what
you're after then passing in the appropriate object (or having some location
they can retrieve it from) sounds like the better plan.

n!
 
Back
Top