My first question: What is the difference between an protected and a public constructor in an abstract class?
My second questions: Does it make sense, if the abstract cl
One possible design that would use a private constructor on an abstract class:
public abstract class BaseClass
{
private BaseClass(Object param)
{
//Do something with parameters
}
//Provide various methods that descendant classes will know how to perform
public static BaseClass FromObject(Object value)
{
//Based on object, choose which type of derived class to construct...
}
private class HiddenDerivedA : BaseClass
{
public HiddenDerivedA(Object value)
: base(value)
{
}
}
private class HiddenDerivedB : BaseClass
{
public HiddenDerivedB(Object value)
: base(value)
{
}
}
}
This pattern is useful if the derived implementations are tightly coupled to the selection logic used to construct them and you wish to provide a high degree of insulation from the rest of your code. It relieves you of the responsibility of having to support other inheritors besides those you explicitly intended and allows you to expose all private state from the base class to your derived classes.