Which design pattern to use for one large method that calls many private methods

I have a class that has a large method that requires many private methods. I think I want to extract these private methods into my own classes for one, because they contain business logic, and I think that they must be publicly available so that they can be tested per unit.

Here is a sample code:

public void handleRow(Object arg0) {
    if (continueRunning){
        hashData=(HashMap<String, Object>)arg0;
        Long stdReportId = null;
        Date effDate=null;
        if (stdReportIds!=null){
            stdReportId = stdReportIds[index];
        }   
        if (effDates!=null){
            effDate = effDates[index];
        }
        initAndPutPriceBrackets(hashData, stdReportId, effDate);
        putBrand(hashData,stdReportId,formHandlerFor==0?true:useLiveForFirst);
        putMultiLangDescriptions(hashData,stdReportId);
        index++;
        if (stdReportIds!=null && stdReportIds[0].equals(stdReportIds[1])){
            continueRunning=false;
        }       
        if (formHandlerFor==REPORTS){
            putBeginDate(hashData,effDate,custId);
        }
        //handle logic that is related to pricemaps.
        lstOfData.add(hashData);
    }
}   

What design model should be applied to this problem?

+3
source share
4 answers

The dramatic refactoring that you describe solely in accordance with your unit testing tools is a really, really bad idea.

.

0

.

#

!

+2

() .

, , .

, . , .

. , .

+1

Your concern for unit testing can be addressed by protecting methods and placing test classes in the same package as the source code.

0
source

Source: https://habr.com/ru/post/1749742/


All Articles