I have notice by looking sample code in iOS, the methods design structures instead of multiple parameters.
Why is that? As far as ease of use, I personally prefer the latter, but as far as performance goes, is there one better choice than the other?
[pencilObj drawPoint:Point3Make(7,9,20)]
[pencilObj drawPointAtX:7 Y:15 Z:25]
Tarun Kumar
13-Dec-2015- Use individuals parameters or objects when it makes sense in the particular scenario.
- Pass objects/structures when it makes sense for the method to understand many/all members of the object.
- Pass objects/structures when you want to validate some rules on the relationship between the various members of the object. This allows you to ensure the consumer of your method constructs a valid object prior to calling your method (thus eliminating the need of the method to validate these conditions).
- Pass individual arguments when it is clear the method makes sense and only needs certain elements rather than the entire object
- Using a variation on your example, a paint method that takes two coordinates (X and Y) would benefit from taking a Point object rather than two variables, X and Y.
- A method retrieveOrderByIdAndName would best be designed by taking the single id and name parameter rather than some container object.