I'm writing Java code and here is the code:
public static void main(String[] args) {
String type = args[0];
if (type.equals("TYPE1")) {
// do something
} else if (type.equals("TYPE2")) {
// do something
}
...
func1(type);
func2(type);
func3(type);
}
public static void func1(String type) {
if (type.equals("TYPE1")) {
// do something
} else if (type.equals("TYPE2")) {
// do something
}
...
}
public static void func2(String type) {
if (type.equals("TYPE1")) {
// do something
} else if (type.equals("TYPE2")) {
// do something
}
...
}
public static void func3(String type) {
if (type.equals("TYPE1")) {
// do something
} else if (type.equals("TYPE2")) {
// do something
}
...
}
As you see, I have to do if...else...
in each function, I believe I can use some design pattern but I don't know which design pattern is the best for this case.
Aucun commentaire:
Enregistrer un commentaire