vendredi 24 mars 2017

Factory instances in GWT

I have a class like so:

public class XmlParserHandlerFactory {

private static XmlParserHandler defaultHandler;
private static XmlParserHandler handler;

public static XmlParserHandler getHandler(){
    if(handler == null){
        //Default behavior.
        initDefaultHandlerIfRequired();
        defaultHandler.initialize();
        return defaultHandler;
    }else{
        handler.initialize();
        return handler;
    }
}

private static synchronized void initDefaultHandlerIfRequired(){
    if(defaultHandler == null){
        defaultHandler = new DefaultXmlParserHandler();
    }
}

public static void setHandler(XmlParserHandler h){
    handler = h;
}

public static void setDefaultHandler(){
    handler = null;
}

For me it seems a bit old style way of writing code? I wondered what options there could be in GWT for creating a nicer looking class? This class obviously works but I think it could be improved.

Thanks for any help

Aucun commentaire:

Enregistrer un commentaire