Inheritage - or what??

  • Thread starter Thread starter Arne Rasmussen
  • Start date Start date
A

Arne Rasmussen

Hi there
I have this problem - might seem stupid to you and a cause of poor design
....but nevertheless it's a problem that i'm facing:

I have 1 to X singletons witch have exactly the same code - but they are in
different namespaces as they hold some information witch belongs to this
namespace.
Anyway they are called in the intizialising of my application and thereby
instantiated - and filled with the proper information .
Now the way i do taht is exactly the same way for all my singletons - and
therby repeated code for each and every.
I would like to have a method which takes a singleton and a ...say
filename... and do the work ...but i can't figure out how to do this - i
have tried with an interface - but as we all now it don't like the keyword
static :-) .....somebody know what to do???? - should mention that i'm a
relative newbee to C#

Thanx in advance
Regards
A. Rasmussen
 
What i have is the following:

using System;

namespace TestAfInstance.TestClass1
{
public class Class1
{
private static Class1 instance;

private string someVariable;

public static Class1 Instance()
{
if (instance == null)
{
instance = new Class1();
}
return instance;
}

public string SomeVariable
{
get{return someVariable;}
set{someVariable = value;}
}
}
}


Now i have several of these class'es but they differ in namespace.
However i found the solution - i have a baseclass implementing the
property SomeVariable wich the singletons inherits i then do the
following to have common code

BaseClass base = <somenamespace>.instance();

and then accesing base.SomeVariable for all the namespaces

Regards
Arne Rasmussen
 
Back
Top