In one recent exam, I was asked 2 questions regarding the code snippet below... The questions are as follows
Identify the design principle violated by the code snippet
Describe the design pattern that solves the design principle violated.
Provide the UML class diagram of the design pattern described in (2) above (Optional)
public class AI{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
String choice = input.nextLine();
if(choice.equals("some text"){
// do something
}
else if(choice.equals("another text"){
// do something
}
else if(choice.equals("extra text"){
// do something
}
...
else{
// do default
}
}
}