D
Dave
Hello all,
I have a class that contains a large number of discrete pieces of state
information. Any combination of these member variables might be valid for a
given object. Any given member variable might be used or unused in a given
object. For each field, there is a FieldIsValid() member function that must
be called before accessing or mutating a given field. If a field is
reported as not valid, it must not be accessed or mutated.
Let me take a quick detour here. I think this is a terrible design, but
it's what I've been tasked to work with. I am the maintainer, not the
original implementer. This class is heavily used, so extricating it and
replacing it with something better designed is not an option. OK, detour
over.
Constructors have been defined for the combinations of fields that have been
needed so far. Now, more combinations of fields are needed. The number of
constructors is liable to grow exponentially. Rather than continuing to
tack on additional constructors in this manner, I would like to come up with
a general scheme to initialize any subset of member variables. Note that I
said "initialize", not "assign". The object needs to be in a usable state
after construction. It is not acceptable to construct it half-baked and
then go call a bunch of mutators for the fields I care about.
I have had some thoughts on this, but I would also like to solicit
suggestions. Any and all suggestions will be appreciated!
Thanks,
Dave
I have a class that contains a large number of discrete pieces of state
information. Any combination of these member variables might be valid for a
given object. Any given member variable might be used or unused in a given
object. For each field, there is a FieldIsValid() member function that must
be called before accessing or mutating a given field. If a field is
reported as not valid, it must not be accessed or mutated.
Let me take a quick detour here. I think this is a terrible design, but
it's what I've been tasked to work with. I am the maintainer, not the
original implementer. This class is heavily used, so extricating it and
replacing it with something better designed is not an option. OK, detour
over.
Constructors have been defined for the combinations of fields that have been
needed so far. Now, more combinations of fields are needed. The number of
constructors is liable to grow exponentially. Rather than continuing to
tack on additional constructors in this manner, I would like to come up with
a general scheme to initialize any subset of member variables. Note that I
said "initialize", not "assign". The object needs to be in a usable state
after construction. It is not acceptable to construct it half-baked and
then go call a bunch of mutators for the fields I care about.
I have had some thoughts on this, but I would also like to solicit
suggestions. Any and all suggestions will be appreciated!
Thanks,
Dave