KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > examples > impl > CalculatorImpl


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.examples.impl;
16
17 import org.apache.examples.Adder;
18 import org.apache.examples.Calculator;
19 import org.apache.examples.Divider;
20 import org.apache.examples.Multiplier;
21 import org.apache.examples.Subtracter;
22
23 /**
24  * Implementation of the {@link org.apache.examples.Calculator}
25  * service interface. Acts as a facade, delegating each operation to other
26  * services. The <code>hivemind.BuilderFactory</code>
27  *
28  * @author Howard Lewis Ship
29  */

30 public class CalculatorImpl implements Calculator
31 {
32     private Adder _adder;
33     private Subtracter _subtracter;
34     private Multiplier _multiplier;
35     private Divider _divider;
36
37     public double add(double arg0, double arg1)
38     {
39         return _adder.add(arg0, arg1);
40     }
41
42     public double subtract(double arg0, double arg1)
43     {
44         return _subtracter.subtract(arg0, arg1);
45     }
46
47     public double multiply(double arg0, double arg1)
48     {
49         return _multiplier.multiply(arg0, arg1);
50     }
51
52     public double divide(double arg0, double arg1)
53     {
54         return _divider.divide(arg0, arg1);
55     }
56
57     public void setAdder(Adder adder)
58     {
59         _adder = adder;
60     }
61
62     public void setDivider(Divider divider)
63     {
64         _divider = divider;
65     }
66
67     public void setMultiplier(Multiplier multiplier)
68     {
69         _multiplier = multiplier;
70     }
71
72     public void setSubtracter(Subtracter subtracter)
73     {
74         _subtracter = subtracter;
75     }
76
77 }
78
Popular Tags