Created
December 19, 2019 22:55
-
-
Save kaansonmezoz/af73387a574a8609023d25ae8d12055a to your computer and use it in GitHub Desktop.
Factory Pattern ~ A Modern Approach - 4 (FileReader)
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
| @Service | |
| public class CsvReader extends FileReader { | |
| public CsvReader(){ | |
| super(FileType.CSV); | |
| } | |
| @Override | |
| public void readFile(String filePath) { | |
| System.out.println(String.format("CsvReader --> Reading file: %s", 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
| @Service | |
| public class ExcelReader extends FileReader{ | |
| public ExcelReader() { | |
| super(FileType.EXCEL); | |
| } | |
| @Override | |
| public void readFile(String filePath) { | |
| System.out.println(String.format("ExcelReader --> Reading file: %s", 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 abstract class FileReader { | |
| private FileType supportedFileType; | |
| FileReader(FileType supportedFileType){ | |
| this.supportedFileType = supportedFileType; | |
| } | |
| public FileType getSupportedFileType(){ | |
| return supportedFileType; | |
| } | |
| public abstract void 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
| @Service | |
| public class PdfReader extends FileReader{ | |
| public PdfReader() { | |
| super(FileType.PDF); | |
| } | |
| @Override | |
| public void readFile(String filePath) { | |
| System.out.println(String.format("PdfReader --> Reading file: %s", filePath)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment