Consider a large program with many different parts that have a single command line interface, as is the case with most applications. How best do I handle passing various command line parameters, that may be meant for various parts of the application, to them?
These parts may be hierarchical, for example, main()
instantiates A (which instantiates B, C) and D (which spawns E), and each of them has specific requirements for command line parameters. There are various possibilities.
- Make global variables for the parameters, set them and then just read them as required. Possibly in a configuration namespace or class or some sort.
- Make a HashMap, which maps the command line arguments, which constitutes members of an Enum, to their values. These are strings initially of course, but each part of the program reads and interprets the types as requires. This map is passed hierarchically with each instantiation.
- Make classes for AConf, DConf, which are then populated by main and passed to A, and D resp., from which they make BConf, CConf, EConf, and pass those configuration objects to B, C, E resp.
and many more.
In a large application with various parts, how is this handled gracefully?
Note: I'm not asking about argument parsing. I'm asking how to send the values to different objects after they've been parsed.