Improving Parameters in the method signatrue

When working to improve method parameters, our goal is to define the parameters in our method signature, such that the resulting method call arguments are clear, easy to understand, and less prone to error.

The first step toward that goal is to define coherent parameter names that clearly describe the purpose of each parameter.

Another way we can indicate the intent of each parameter is to add XML document comment.
In addition, to specify the method summary, we can add a param tag for each parameter and provide detailed parameter description.
This information appears in the intelisence, helping any developer using our method in the appropriate arguments.

Limiting the number of the parameters can also make method easier to use.


Defining a logical and consistent parameter order can also make our method signature easier to use.
One recommended technique is to start with the parameters that are acted upon or are key to the operation, in our PlaceOrder method, we are placing the order for a particular product, so that product is the first parameter.

Next, define the parameters required for the operation in the order of importance, in our PlaceOrder method, the quantity is required for the operation.

Then add any flag in order of their importance, In our PlaceOrder method, these are the includeAddress and SendCopy parameters.

Lastly, add any optional parameters.



Comments

Popular posts from this blog

Introduction