jeudi 14 juillet 2016

Combination of factory and builder pattern?

I have code such as this:

public class ProcessorBuilder {  
   enum Type {  
       X,  
       Y,
   }  

   private static HashMap<Type, Processor> processors = new HashMap<>();  
   public static void buildProcessors(int arg1, String arg2, CustomObject arg3) {  
      processors.put(Type.X, new ProcessorImpl1(arg1, arg2));  
      processors.put(Type.Y, new ProcessorImpl2(arg3));    
   }  

public Processor getProcessor(Type type) {  
   return processors.get(type);  
}  

Where I have the interface:

public interface Processor {  
   public ArrayList<String> process(ArrayList<CustomObject> input);  
}

Seems that the code is not that clean. I feel that I need somekind of combination of factory and builder pattern.
What am I doing wrong here or how can I improve this?

Aucun commentaire:

Enregistrer un commentaire