public class Base<S>
{
public static Derived<S, T> Create<T>()
{
return new Derived<S, T>(); //if not public, I wont get it here.
}
}
public class Derived<S, T> : Base<S>
{
public Derived() //the problem, dont want it public
{
}
}
This is the basic structure I have got.
Requirements:
1) I don't want an instance of Derived<,>
to be constructed calling Derived<,>
class at all, be it via constructor or a static method. I want it to be created only via Base<>
. So this is out:
public class Derived<S, T> : Base<S>
{
Derived()
{
}
public static Derived<S, T> Create()
{
return new Derived<S, T>();
}
}
2) Derived<,>
class itself must be public (which means I can't private nest Derived<,>
inside Base<>
). Only then I can return Derived<,>
from the static Create
method in Base<>
.
Is it possible?
`, which happens to actually create an instance of the derived type? Do callers really need the derived type? If they need some members of it, could that be described in an interface implemented by the derived type?– Jon Skeet Apr 18 '13 at 21:40