here a rougth code example to my problem:
class FooMaster
{
private static FooChildBase GetFooChild(int number)
{
switch(number)
{
case 1:
return new FooChild1();
case 2:
return new FooChild2();
default:
throw new NotImplementedException("...");
}
}
public static string GetFooChildText1Value(int number)
{
FooChildBase fooChild = GetFooChild(number);
return (fooChild?.Text1) ?? throw new NullReferenceException("...");
}
...
class FooChild1 : FooChildBase
{
internal override string Text1 { get; } = "Test"
public static void Test()
{
//Do something
}
}
class FooChild2 : FooChildBase
{
internal override string Text1 { get; } = "Test"
}
abstract class FooChildBase
{
internal abstract string Text1 { get; }
}
}
What i want to accomplish:
You should:
EDIT:
The Types FooChild1 and FooChild2 must be known from outside because you need to be able to call individual public static methods directly (I don't want to make methods that only call the next method)
Update:
In the End I created another class-library and defined the constructor as internal. That way it's only accessable in this assembly.
The proposed interface solution could also have worked, but I would have had to create a separate interface for each class.
Thanks for all the quick answers!