design patterns - How could I improve this C++ code -


i want suggestion on following pseudo-code. please suggest how improve it, whether or not use design patterns.

 // i'm receiving string containing : id operation arguments data    = read(socket); tokens  = tokenize(data," "); // tokenize string based on spaces if(tokens[0] == "a") {    if(tokens[1] == "some_operation") {       // here goes code some_operation , use remaining tokens arguments function calls    }    else if(tokens[1] == "some_other_operation") {      // here goes code some_other_operation , use remaining tokens    }    ...    else {      // unknown operation    } } else if(tokens[0] == "b") {    if(tokens[1] == "some_operation_for_b") {      // operation b    }    else if(tokens[1] == "yet_another_operation") {      // yet_another_operation b    }    ...    else {      // unknown operation    }  } 

i hope point . thing have large number of id's , each has it's own operations , , think it's kinda ugly have 10 screens of code containing lot of if's , else if's.

have class each id implements common interface. strategy pattern iirc.

so you'd call (pseudo)code like:

strategyfactory.getstrategy(tokens[0]).parse(tokens[1..n])


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -