001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.examples.impl;
016
017 import org.apache.examples.Adder;
018 import org.apache.examples.Calculator;
019 import org.apache.examples.Divider;
020 import org.apache.examples.Multiplier;
021 import org.apache.examples.Subtracter;
022
023 /**
024 * Implementation of the {@link org.apache.examples.Calculator}
025 * service interface. Acts as a facade, delegating each operation to other
026 * services. The <code>hivemind.BuilderFactory</code>
027 *
028 * @author Howard Lewis Ship
029 */
030 public class CalculatorImpl implements Calculator
031 {
032 private Adder _adder;
033 private Subtracter _subtracter;
034 private Multiplier _multiplier;
035 private Divider _divider;
036
037 public double add(double arg0, double arg1)
038 {
039 return _adder.add(arg0, arg1);
040 }
041
042 public double subtract(double arg0, double arg1)
043 {
044 return _subtracter.subtract(arg0, arg1);
045 }
046
047 public double multiply(double arg0, double arg1)
048 {
049 return _multiplier.multiply(arg0, arg1);
050 }
051
052 public double divide(double arg0, double arg1)
053 {
054 return _divider.divide(arg0, arg1);
055 }
056
057 public void setAdder(Adder adder)
058 {
059 _adder = adder;
060 }
061
062 public void setDivider(Divider divider)
063 {
064 _divider = divider;
065 }
066
067 public void setMultiplier(Multiplier multiplier)
068 {
069 _multiplier = multiplier;
070 }
071
072 public void setSubtracter(Subtracter subtracter)
073 {
074 _subtracter = subtracter;
075 }
076
077 }