1 3 package org.jmock.examples.calculator.expression; 4 5 import org.jmock.examples.calculator.CalculatorException; 6 import org.jmock.examples.calculator.Environment; 7 import org.jmock.examples.calculator.Expression; 8 9 10 public abstract class BinaryOperator implements Expression 11 { 12 13 private Expression left, right; 14 15 protected BinaryOperator( Expression left, Expression right ) { 16 this.left = left; 17 this.right = right; 18 } 19 20 public double evaluate( Environment environment ) 21 throws CalculatorException { 22 return operator(left.evaluate(environment), 23 right.evaluate(environment)); 24 } 25 26 protected abstract double operator( double leftArg, double rightArg ) 27 throws CalculatorException; 28 } 29 | Popular Tags |