みなさん、こんにちは。私は2つのJavaプログラムに取り組んでいます。文字通り、2つの違いは、2次元配列を定義するbeginningステートメントだけです。以下の例では、コードを大幅に短縮しています。
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) {
}
}
そしてここの2番目のクラス:
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*/
}
}
問題は、唯一の違いが「マスター」2次元配列である1つのクラスを取得するためにどのようにリファクタリングできるかということです。フックメソッドなどはここではばかげているでしょう。プログラムが行うことで変更が必要なことは何もないからです。どう思いますか?