Created
December 19, 2019 22:31
-
-
Save kaansonmezoz/80cd0dad35eda76f2cb622faa82c5568 to your computer and use it in GitHub Desktop.
Factory Pattern ~ A Modern Approach - 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FileOperations { | |
| private FileReaderFactory readerFactory; | |
| // some code here | |
| public String readFile(String filePath){ | |
| return readerFactory.createFileReader(filePath).readFile(FilePath); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FileReaderFactory { | |
| // other necessary methods are here | |
| public FileReader createFileReader(String filePath) { | |
| FileReader reader; | |
| if (isExcelFile(filePath)) { | |
| reader = new ExcelReader(); | |
| } | |
| else if(isPdfFile(filePath)) { | |
| reader = new PdfReader(); | |
| } | |
| else if(isCsvFile(filePath)) { | |
| reader = new CsvReader(); | |
| } | |
| else { | |
| throw new UnsupportedFileException("..."); | |
| } | |
| return reader; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment