Skip to content

Instantly share code, notes, and snippets.

@kaansonmezoz
Created December 19, 2019 22:55
Show Gist options
  • Save kaansonmezoz/af73387a574a8609023d25ae8d12055a to your computer and use it in GitHub Desktop.
Save kaansonmezoz/af73387a574a8609023d25ae8d12055a to your computer and use it in GitHub Desktop.
Factory Pattern ~ A Modern Approach - 4 (FileReader)
@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));
}
}
@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));
}
}
public abstract class FileReader {
private FileType supportedFileType;
FileReader(FileType supportedFileType){
this.supportedFileType = supportedFileType;
}
public FileType getSupportedFileType(){
return supportedFileType;
}
public abstract void readFile(String filePath);
}
@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