I find my self repeating a single line of code in child constructors, which are passed two variables. The first of these variables is always used to initiate a protected variable (defined in the parent class). I was wondering if there is a way for me to do that assignment in the parent constructor – which is then inherited, and do the rest of the assinments for the child class in each of the respective constructors (in the child classes)
is this possible? and is this good practice?
many thanks
If I understand you correctly, you need something like this
I would recommend to keep param1 and param2 private and expose them to derived classes via methods, though it depends of your particular task at hand.