Let me know the better approach of writing the code as it has become difficult to maintain, please ignore the naming conventional, it has lots of if conditions which is hard to maintain.
Better approach is recommended.
Thanks
private void startQuestion(String tttt) { // questionTemplate --------------------------------------------------------------- if(isEnable("xxxxx")){ // yyyyy if(isEnable("yyyyy")){ if("zzzz".equalsIgnoreCase(tttt)){ enableFlag("QuestionUserRole"); xxxxxUserRole=new SAXQuestionUserRole(); } }else if("useryyyyy".equalsIgnoreCase(tttt)) { enableFlag("yyyyy"); useryyyyy = new LinkedHashSet<SAXQuestionUserRole>(); } // kkkk if(isEnable("kkkk")){ if("xxxxxCustomerCategory".equalsIgnoreCase(tttt)){ enableFlag("xxxxxCustomerCategory"); xxxxxCustomerCategory=new Lxxxxx(); } }else if("kkkk".equalsIgnoreCase(tttt)) { enableFlag("kkkk"); kkkk = new LinkedHashSet<Lxxxxx>(); } // lversion else if(isEnable("lversion")){ // QRRV if ("QRRV".equalsIgnoreCase(tttt)) { enableFlag("QRRV"); QRRV = new SAXQLV(); } } else if ("lversion".equalsIgnoreCase(tttt)) { enableFlag("lversion"); lversion = new LinkedHashSet<SAXQLV>(); } // newLogicalVersion else if ("newLogicalVersion".equalsIgnoreCase(tttt)) { enableFlag("newLogicalVersion"); newLogicalVersion = new SAXQLV(); } // programs --------------------------------------------------------------- else if(isEnable("programs")){ // xxxxxProgram if ("xxxxxProgram".equalsIgnoreCase(tttt)) { enableFlag("xxxxxProgram"); xxxxxProgram = new SAXxxxxxProgram(); } }else if ("programs".equalsIgnoreCase(tttt)) { enableFlag("programs"); xxxxxPrograms = new LinkedHashSet<SAXxxxxxProgram>(); } }else if ("xxxxx".equalsIgnoreCase(tttt)) { enableFlag("xxxxx"); xxxxx = new SAXxxxxx(); }
I would like your thought also....................
One my friend suggested me to go for the reflection....
His comments is below..
My suggestion is to reduce no of "if" statements. One of my idea is to do it is using Java reflection APIs.
Based of SAX parsing input i.e "tttt", the handler dynamically invokes respective method, thus we can eliminate lot of "if" statements (Also code can be modular & readable using your Handlers).
http://java-source.net/open-source/rule-engines