简体   繁体   中英

Good practice to change a method signature

I have a situation where I declare a method say

public String getData(WebDriver driver, int iRowNumber)

I am calling this method from a number of other test case methods. Now I feel the necessity to change the number of parameters and include a third parameter. It is obviously going to throw error in all the previous test case methods. How do I handle this situation? I don't want to create another method with the same name and different number of arguments (Polymorphism) as I have to use the modified method in the previous test methods as well.

Is there a way by which I can take care of this?

The best solution is to create a new method with three arguments:

public String getData(WebDriver driver, int iRowNumber, Object third)

This method should have a new logic. The old method should call a new method with default arg:

public String getData(WebDriver driver, int iRowNumber) {
    getData(driver, iRowNumber, DEFAULT_VALUE);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM