Created
December 19, 2019 22:11
-
-
Save kaansonmezoz/739da0c9a185b542b5fd9aa3d23069cc 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 CsvReader implements FileReader { | |
| // some code here | |
| public String readFile(String filePath) { | |
| // ... | |
| return fileContent; | |
| } | |
| } |
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 ExcelReader implements FileReader { | |
| // some code here | |
| public String readFile(String filePath) { | |
| // ... | |
| return fileContent; | |
| } | |
| } |
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 { | |
| // some code here | |
| public String readFile(String filePath){ | |
| FileReader reader; | |
| if(isPdfFile(filePath)){ | |
| reader = new PdfReader(); | |
| } | |
| else if(isExcelFile(filePath)) { | |
| reader = new ExcelReader(); | |
| } | |
| else if(isCsvFile(filePath)){ | |
| reader = new CsvReader(); | |
| } | |
| else { | |
| throw new UnsupportedFileExtension("..."); | |
| } | |
| return reader.readfile(filePath) | |
| } | |
| private String readPdfFile(String filePath) { | |
| // some code here | |
| return fileContent; | |
| } | |
| private String readExcelFile(String filePath) { | |
| // some code here | |
| return fileContent; | |
| } | |
| } |
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 interface FileReader{ | |
| public String readFile(String 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 PdfReader implements FileReader { | |
| // some code here | |
| public String readFile(String filePath) { | |
| // ... | |
| return fileContent; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment