Integrating flexibility into class behavior.
When designing class behavior, knowing ahead of time how that function will need to be used is sometimes difficult.
For example, when defining the function signature how do you know in what order the parameters should be arranged and what if that makes a difference to the user?
The C# language now overcomes this challenge with a new feature to the 4.0 specification called “parameterless functions” which allow each parameter to be defined with a default value.
This default value assignment allows the user to pass arguments in any order by simply specifying with each argument the parameter to which it will be used.
To illustrate this feature, I’ll begin with a simple Person class.
To enable this feature within the constructor during object instantiation, I only need to provide a default value for each parameter.
To leverage the flexibility of passing arguments in any desired order, I simply define each argument’s parameter when calling the function.
Notice in this example, I’m instantiating two Person objects while passing arguments in two different orders.
This flexibility is particularly useful when the data being consumed might have fields at different orders, such as with text files.