簡體   English   中英

減少傳遞給方法的參數數量

[英]Reduce number of arguments being passed to a method

要求:我正在將圖像從我們的系統轉換為PNG格式。 只要圖像是CMYK編碼或尺寸小於500 * 500(更多標准),圖像轉換就應該失敗。 每次運行后,應發送一封包含報告的電子郵件。 該功能運行良好,正在重構報表生成器代碼。 我基本上是按照構建器模式來構建報告。 以下是我的代碼片段:

ImageProcessor:

public String processImage(File imageToProcess, String name, String temp_location, String boxLocation, String id, ReportContent missingStyle, ReportContent missingImage, ReportContent unSupportedEncoding, ReportContent imageSize, List<String> missingStyleNames, List<String> missingImageNames, List<String> unSupportedEncodingNames, List<String> imageSizeNames) {
    // The code process an image and if an image fails then it add that failed image to appropriate report content object.
}

我正在從我正在創建ReportContent和Lists實例的服務中調用上述方法。 我想減少傳遞給此方法的參數數量。 一個選項是代替單個ReportContent,我可以傳遞一份Report Content列表。 這種方法的問題是,我還要從proessImage方法中調用其他方法,因此我需要將整個列表再次傳遞給該方法。 我想使代碼更具可讀性並降低復雜性。 如果需要,我很樂意提供更多的代碼片段。

有什么建議么?

如果你想讓代碼更具可讀性,我建議最好創建一個ClassWrapper,並在其中放置一個帶有所有這些方法的構造函數。 這樣,你只需要調用構造函數包裝器,而不是多次使用相同的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM