Bo Persson <
b...@gmb.dk> wrote:
> The nice and clean solution IS to pass the values needed as parameters
> to the constructor.
>
> The base class might then even store the values it is passed and you
> don't have to make getValues virtual.
There are many such virtual functions, which derived classes can
optionally specialize in order to affect how the base class behaves.
It wouldn't make much sense to make them all mandatory, and have the
base class needlessly increase its own size by storing all of those
values within itself (especially since these are often values that
are not tied to a specific object, but are the same for all objects
of the same derived type.)
The values in question shouldn't be added to the public constructor,
because they are not a business of the outside code. It's an internal
implementation detail.
I suppose I could make an overloaded protected constructor just for
this purpose, but this is also somewhat dubious design, because I'm
now making the protected interface less abstract (from the perspective
of derived classes). Now the derived class would need to "know" that
the base class requires the value in its constructor. If in the
future the base class constructor is changed to require another
value, all the derived classes would need to be changed as well
(even if that value is one that's already handled by an existing
virtual function). It also feels like borderline code repetition
(because the derived class needs to be passing the same value to
the base class in two places).