Using the ArgumentReader
The ArgumentReader
abstracts the argument, and makes it easier to retrieve information from it. The information can be retrieved and interpreted from within our method to create the actual Person
instance we want to return.
Because we know the constructor takes a string
and an int
, we can expect the provided argument to be constructed in a way that allows us to retrieve those values.
Each component of the argument is being read in order. This means that once a component has been read, it can not be read again. It simply functions as a queue. This makes it so you do not have to specify any indices, but it also means you have to store the values in order.
With the simple method, We can now support parameters of type Person
. The input string could look like this: hello (Bob, 52)
, which would result in a new instance of Person
, with name
set to Bob, and age
set to 52.
Last updated
Was this helpful?