大家好:我正在开发两个java程序,实际上两者之间的唯一区别是定义二维数组的开始语句。我在下面的例子中大大缩短了代码:
public class Qwerty {
/** this is what needs to be replaced */
private static char master[][] = {
QwertyKbd.lIndex,
QwertyKbd.lMiddle,
QwertyKbd.lRing,
QwertyKbd.lPinky,
/** and so forth in this fashion */
};
public static int[] analyze(String file) {
}
public static void split(char c) {
}
}
和这里的第二堂课:
public class Dvorak{
/** this is what needs to be replaced */
private static char master[][] = {
/** various definitions, eliminated for conciseness */
};
public static int[] analyze(String file) {
/** this is the same*/
}
public static void split(char c) {
/** this is the same*/
}
}
问题是我如何重构以获得唯一不同的是“主”二维数组的类?钩子方法等在这里会很愚蠢。因为程序没有任何需要修改的地方。你怎么看?