Skip to content

Instantly share code, notes, and snippets.

@kaansonmezoz
Last active December 19, 2019 23:00
Show Gist options
  • Save kaansonmezoz/30e485c048ddc1e27166a146f4061690 to your computer and use it in GitHub Desktop.
Save kaansonmezoz/30e485c048ddc1e27166a146f4061690 to your computer and use it in GitHub Desktop.
Factory Pattern ~ A Modern Approach - 4 (FileReaderFactory)
@Service
public class FileReaderFactory {
private EnumMap<FileType, FileReader> fileReaders;
public FileReaderFactory(List<FileReader> fileReaderList){
fileReaders = new EnumMap<>(FileType.class);
fileReaderList.forEach(reader -> fileReaders.put(reader.getSupportedFileType(), reader));
}
public FileReader getFileReader(String extension){
return fileReaders.get(FileType.fileTypeOf(extension));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment