返回类型不同时如何进行抽象/设计模式

时间:2019-03-12 19:30:02

标签: design-patterns

public final class ExcelReader{
    /**
     * @param file File object of the excel file
     * @param sheetNumbers integer array holding the sheet offset/numbers. Note offset starts from 0. So 0 is first sheet.
     * @return List of Sheets, where each <Sheet> hold a list of Rows, where each <Row> holds a list of Columns
     */
    public List<List<List<String>>> read(File file, final int ... sheetNumbers){
        //return List<List<List<String>>>
    }
}

public final class CSVReader{
    /**
     * @param file File object of the excel file
     * @return List of Rows, where each <Row> holds a list of Columns
     */
    public List<List<String>> read(File file){
        //return List<List<String>>
    }
}

将来我可能会有HTML阅读器或其他阅读器

我正尝试将Strategy与具有通用接口的工厂设计模式一起使用

public interface FileReader {
    //Return type is different for different readers
    public <TODO> read(File file); 
}

但随后意识到返回类型不同,谁知道HTMLReader可能具有哪种返回类型,甚至可能是自定义对象。

我不确定如何将这些东西重新组合在一起。有人可以说明一下。

我确实找到了这个讨论Design Patterns - what to use when the return type is different,但是我不明白如何在自己的情况下使用它。

感谢您阅读

0 个答案:

没有答案
相关问题