Function method parameter format related to business-advantages and disadvantages of using specific variable parameters or containers such as map

Source: Internet
Author: User

In the function method interface design related to the business, there are two types of function parameters:

1. Pass specific values, such as Save (int id, char name, char value ).

Advantage: when the number of parameters is small (less than three), it is easier to call and function parameters are relatively clear;

Disadvantage: it cannot adapt to the changing needs of the number of parameters;

2. pass through containers such as map, such as Save (hashmap m ).

Advantage: it can meet the changing needs of parameter types and numbers;

Disadvantage: it is not too intuitive for callers.

Summary

1. When the number of function parameters is less than three, the function business function is very simple. For example, it is reasonable to use the first method to obtain Objects Based on ID.

2. When there are more than three function parameters, different combinations of parameters are often transferred each time. The second method should be used for parameter transfer, in this case, calling a function is more convenient than using the first method, and can better adapt to subsequent business changes.

-By a farmer-

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.