Java
--
Questions
--
Followers
Top Experts
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();
}
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
http://java-source.net/open-source/rule-engines
reduce the cyclomatic complexity on the code like so many if conditions






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Accepted answer: 0 points for roy_sanu's comment #a39722056
for the following reason:
got the solution from the above link

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
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).
Hope this helps!
Java
--
Questions
--
Followers
Top Experts
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.