On Your Mark
2013年10月5日土曜日
デザインパターン 設計(Java)
public class Expression { public int result() { return new Plus(new Operand(3), new Multiply(new Operand(2), new Operand(5))).execute(); } } public class Multiply implements Operator { private Operand value1 = 0; private Operand value2 = 0; public Multiply(Operand value1, Operand value2) { this.value1 = value1; this.value2 = value2; } public int execute() { return Operand.execute() * Operand.execute(); } } public class Plus implements Operator { private Operand value1 = 0; private Operand value2 = 0; public Plus(Operand value1, Operand value2) { this.value1 = value1; this.value2 = value2; } public int execute() { return Operand.execute() + Operand.execute(); } }
QooQ
0 件のコメント:
コメントを投稿