I wanted to try the factory pattern and was able to implement it, but when generating for more than a few classes, I thought it would be ugly !! therefore any clarity or suggestions would be truly appreciated ...
My superclass:
public abstract class Output { public abstract void generate(Data dat); }
I got other classes coming out of Output, like
public class generateXML extends Output{ . . . }
My question is related here:
public class generatorFactory(){ public Output generate(String str){
// or get the object as an argument of type (Object obj)
if(str.equals("xml"){ return new generateXML(); } else if......... ...... }
Is there any way to determine the type of a subclass, avoiding checking for each type?
source share