Chapter 14 - Successive Refinement
- Argument parser
- Args class constructed with format string describing arguments and list of arguments
- Methods to get arguments as type, if type is wrong get an exception
- Initial design before refactor
- Hash map for arg name -> value for every argument type
- Adding a new type requires updating multiple parts of Args
- Hash map
- Parsing the schema definition
- Parsing the command line based on schema definition
- Getting the value
- Was built incrementally, first version only accepted bools
- Logic for bool values was duplicated for other types
- ArgumentMarshaller class
- Want to move type switches out of Args
- Easier to add a new type by defining a new class with all the logic in one place and dispatching using inheritance
- Refactoring behaviour into ArgumentMarshaller class, which will later be pushed into derivatives - incrementally with tests rather than all at once
- Initially kept separate maps but wrapped the value with the marshaller to handle parsing, getting
- Then refactored again into one map with dispatching
- Also done one type at a time
- Setting was done after
- Setting values
- Bool arguments are just set to true
- Setting Integer and string arguments need the next value in the array to set their value
- Currently using the index and array
- Use an Iterator instead so the marshaller set only needs one argument instead of two
- Exceptions
- Another responsibility for the Args class
- Move into an argsException class
- Also throwing ParseException from Integer.parseInt, which doesn't belong to us