Parameter List vs Structure

Source: Internet
Author: User

When passing values to a function, we can either use the parameter list or define a structure. In my recent work, I think the previous method is better.
For example:Code:

// Pass value through parameter list
Public   Void Create ( Long Param1, Long Param2, Long Param3)
{
..
}

// Pass value through Structure
Public   Sealed   Class Classojbect
{
Public LongParam1;
Public LongParam2;
Public LongParam3;
}
Public   Void Create (classobject OBJ)
{
..
}

In the first method, if we add a parameter to the parameter list, we need to modify many other places in the project, because it is a public method, compile immediately, and report an error immediately.
In the second method, if we add a parameter to classobject, we do not seem to need to modify anything, because the parameter only references the classobject address, not the member variable in it, therefore, there will be almost no errors during compilation.
On the surface, the second method is better, because after the system is modified, the system itself has no adverse effect. However, the second method may cause bugs.
Because create is a public method with global calls, we must ensure that all functions that call the create method can assign values to new parameters in create. The second method cannot provide such a guarantee. because the system has no response, we must find all the places where create is called by searching, and assign values to the new member variables of the classobject object.
The first method can solve this problem well, because we can accurately find the place to call create through the error information generated during system compilation.
Although the first method changes a lot and may affect other modules, it blocks all the changes in the compilation phase. I don't think anyone will want to introduce new bugs because of changes to somewhere in the system.

But the second method is useful. However, this topic has ended. I hope your colleagues can share their opinions.

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.