In my application I fetch files from the user and process it.Im to limit to a certain scope of file types and each one of these has a different processing approach.How can I design the application in order that when a new type of file is added, I have to change few to no lines in the controller classes.Should I be using an Adapter? Wouldn't that be just delegating change responsabilities to another class?Should I make a representative class for files and deal with them that way?If possible, provide a (generic) implementation example. It might help to know that Im designing a Spring MVC application and loading files with multipart files. Also, Im checking file type through extension name in the loading file controller [this might have to change].
Pattern for dealing with different File Types
design patterns;object oriented design;file handling
Decorators would fit, one implementation for each of the types, one more as a facade (or dispatcher ? not sure about the term here) routing to the proper implementation.The facade and the multiple decorator should implements the same interface, here is an example : public interface FileProces{    public void process(File file);    public boolean canProcess(File file);}Each decorator should handle his own type of file : public class JpgFileProces implements FileProces{    public void process(File file){        if(!canProcess(file)){            throw new IllegalArgumentException();        }        ...    }    public boolean canProcess(File f){        return f.getContentType.equals(image/jpeg);    }}Then the Facade : public FacadeFileProces{    public Set<FileProcess> setProcess;    public void process(File file){         for(FileProcess process : setProcess){                if(process.canProcess(file)){                     process.process(file);                     break;// you can either do that of for more security, either ensure that you have only one processor and not multiple that are registered.               }         }    }    public boolean canProcess(File file){       for(FileProcess process : setProcess){           if(process.canProcess(file)){               return true;           }       }       return false;    }}Note : DavidPacker in his comment talked about factory : his solution is more usefull is your FileProcessor are not stateless. If they're not, using a factory returning only singletons is the same that I did, I'm just masking the fact that I have sublayers.