I have an api method I need to call. It has 10 parameters. I have attempted to make a class that holds all the information the method requires. Can I then simply pass the object into the method?
myAPIMethod(myClass);
Does it work that easily?
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.
No, it doesn’t work that way. If a method has 10 parameters, you will have to pass 10 arguments to it.
If you have control of the API, you can refactor it to accept a single object instead.
If you don’t have control of the API, you can write a method along the lines of
Then your code can use your class and this method to invoke the API. It could be a cleaner approach than invoking the API method directly with 10 arguments in multiple places in your application. But, this depends on what the method is and how you’re using it.