Port of schuchert.wikispaces.com


Template Method Pattern Hints

Template Method Pattern Hints

Example of BinaryOperator

public abstract class BinaryOperator implements Operator {
    @Override
    public void execute(RpnStack values) {
        BigDecimal rhs = values.pop();
        BigDecimal lhs = values.pop();
        
        BigDecimal result = calculate(lhs, rhs);
        
        values.push(result);
    }

    abstract BigDecimal calculate(BigDecimal lhs, BigDecimal rhs);
}

Example of Add

public class Add extends BinaryOperator {
    @Override
    BigDecimal calculate(BigDecimal lhs, BigDecimal rhs) {
        return lhs.add(rhs);
    }
}

Comments

" Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.