Both the approaches have their own pros and cons. What is better in a scenario depends a lot on the use-case at hand.
Pro Multiple params, Con Object reference:
- Caller not bound to a specific classnot bound to a specific class, it can pass values from different sources altogether
- Object state is safe from being modified unexpectedlysafe from being modified unexpectedly inside the method execution.
Pro Object reference:
- Clear interfacingClear interfacing that the method is bound to Object reference type, making it difficult to accidentally pass unrelateddifficult to accidentally pass unrelated / invalid values
- Renaming a field/getterRenaming a field/getter requires changes at all invocations of the method and not just in its implementation
- If a new property is addednew property is added and needs to be passed, no changes required in method signature
- Method can change object statemutate object state
- Passing too many variables of similar primitive types makes it confusing for the caller regarding the order confusing for the caller regarding the order (Builder pattern problem)
So, what needs to be used and when depends a lot on the use-cases
- Pass individual parameters : In general, if the method has nothing to do with the object type it is better to pass individual parameternothing to do with the object type it is better to pass individual parameter list so that it is applicable to a wider audience.
- However,Introduce new model object : if the list of parameter grows to be large(more than 3), it's better to introduce a new model object belonging to the called API (builder pattern preferred)
- Pass Object Reference : If the method is related to the domain objects, then its better from maintainability and readability point of view to pass the object references.