I am wondering what is the best practices to write method that takes at least three parameters of the same type. The problem is that you can mix up parameters when using such method. For example
method(int userId, int productId, int weight, int price)
The only solution I see is to use some holder class(maybe with builder pattern used) and passing it as method parameter.
The best practice is to use clear parameter names (and possibly clarifying them in the Javadoc). If there are too many parameters, a separate object is better.
If the caller of the method can't distinguish between different (well named) parameters, then maybe he shouldn't be calling the method in the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With