On 04/09/2004, Phlip wrote:
> Why do you need hundreds of data elements. Their redundance typically
> indicates you have overlooked the possibility of a better abstraction.
See below.
> > Someone adds
> > s237a to the class, and they have to remember to add
> > s237a("string237a") to the list. And if they forget, the code still
> > compiles.
>
> Here's the Variable State Pattern in C++:
>
> typedef map<string, string> variables_t;
> variables_t variables;
> variables["s237"] = "string237";
> variables["s238"] = "string238";
> variables["s239"] = "string239";
> ...
> variables["s999"] = "string999";
>
> That provides more flexibility. You can store the strings in a file,
> iterate thru the map and affect each one, and generally distribute
> the effort of initializing them. No syntactic sugar will make that
> easy.
That would solve the problem as described.
Unfortunately in order to get a clear example it seems that I've
oversimplified the problem.
The class I'm designing is, in part, a parameter manager which fits in
to a large distributed system. The large distributed system is a given
and I have no control over it.
The parameters are of different types, from bools to lists of complex
objects.
The parameter manager will be required to do a number of things:
1/ Accept a parameter by name
2/ Accept a parameter by number
3/ Save a selection of its parameters to nvram
4/ Give a list of all its parameter names
.... etc
The parameter manager will also be a base class for extended parameter
managers which will handle extra parameters over and above those
available in the base class.
I'm not sure how I'd implement this without having a list (or series of
lists) of the parameter names, types, numbers, values and other
properties, all of which has to be initialised somewhere.
--
Simon Elliott
http://www.ctsn.co.uk