Why using methods with multiple entries is a better practice
21 October 2010
Why using methods with multiple entries is a better practice 2 of 2
Methods with multiple parameters can be used in many types of applications. Any time that you have a situation where you need to enter multiple values for an item you would want to use this method of using multiple parameters. For example they can be used in a database input application where you want to enter several strings of information into the database without having to write individual entries for each string value that is required. As in: private static void addName(String name, String address, String zipcode)
This example would allow for the entry of three values into a database for a client and save the programmer from having to three individual lines of code to retrieve each of the string value. This method is much more efficient and easier to trouble shoot than creating the individual entries.
Another example for use of this use of multiple parameters would be in a point of sale type environment where you need to enter multiple values for an item that a customer is purchasing from an online store. You may need to collect entries for the item description, sku, price and weight. This could be done with a method like: private static void addItem(String description, int sku, Double price, Double weight)
This example could even be expanded to include other specifics about the item like color and size or any number of other parameters that may pertain to that item. Again in this example you can see that it is much more efficient than creating an individual line of code to collect each value required for the purchase.