I have a baseclass named Entity. All stuff like Customer,Invoice,Article
and so on will derive from this class.
I have fields in the base class like "tablename" and "primarykeyname"
which is used to create the database operations on the class.
now the question is: how do I enable my base class to initialize these
values, but the values must not be changeable at a later time.
I do not want the variables to be set as in the baseclass' ctor:
public Derived():base("customer", "custID") // I don't want it this way
because I want to be able to add more variables at a later time without
breaking derives classes.
additionally I do not want these variables to reside directly in my
entitybaseclass but instead in a separate nested class which should be
accessible from outside the class with a property:
class BaseEntity
{
EntityParams parms = new EntityParams();
public EntityParams EntityParameter
{
get { return parms; }
}
}
But now the question is, how do I ensure that this object is NOT
modified after initialisation of the BaseEntity instance?
sure I could put Exceptions in each property.
And I do not want initialize the EntityParams class like this:
EntityParams parms = new EntityParams(param1, param2, param3...);
but instead I want to set the properties separately (so that later
additions of parameters do not break derived classes).
The funny thing is that I had a few week an idea of inventing
named/optional parameters which would solve exactly that problem :)
Is there a good solution for that? Did you ever stumbled across such a
problem?