Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

オブジェクト指向プログラマーがゾッとする実話

とあるJava開発での設計の話。

お弁当箱の中におにぎりが入っていて、
おにぎりは米と海苔と塩で出来ている
というような感じの構造の設計を依頼された。

class LunchBox {
  private RiceBall riceBall;//おにぎり
  //略
}

class RiceBall {
  private Rice rice;//米
  private Laver laver;//海苔
  private Salt salt;//塩
  //略
}

利用時のコードは以下。

LunchBox lunchBox = new LunchBox();
RiceBall riceBall =  new RiceBall();
Rice rice = new Rice();
Laver laver = new Laver();
Salt salt = new Salt();
riceBall.setRice(rice);
riceBall.setLaver(laver);
riceBall.setSalt(salt);
lunchBox.setRiceBall(riceBall);

これにUMLもつけて説明したら意味わからんと言われて
以下のようにしろって言われてしまったのです。

List<List<String>> parentList = new ArrayList<List<String>>();
List<String> childList1 = new ArrayList<String>();
childList1.add("おべんとう");
childList1.add("おにぎり");
childList1.add("こめ");
parentList.add(childList1);

List<String> childList2 = new ArrayList<String>();
childList2.add("おべんとう");
childList2.add("おにぎり");
childList2.add("海苔");
parentList.add(childList2);

List<String> childList3 = new ArrayList<String>();
childList3.add("おべんとう");
childList3.add("おにぎり");
childList3.add("塩");
parentList.add(childList3);

((((;゚Д゚))))ガクガクブルブル