I was wondering, which way is better in terms of performance and memory usage?
Passing only the needed parameters for a specific function or its the same to pass an object with 30 properties but the function will use 3 of them?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should not decide this on the basis of performance. The performance difference is so minimal to be negligible. (But to answer your question, passing the object is faster if it’s a reference type; passing the parameters is faster if the large object is a value type.)
You should decide this on the basis of what your code means. If the method is logically related to the object with 30 properties, then it makes sense for the method to take the object. You might also want to think about whether any future changes to the method might need access to more of the properties.
If the method is logically unrelated to the object, and the three values you pass in are just pieces of information for the method, you should pass them in as separate parameters. You should also think about whether any future code calling the method may want to pass in different values than those three properties from that specific object.