author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Tue, 07 Oct 2008 11:05:34 +0200 | |
changeset 45 | 251d0ed461fb |
parent 29 | task2/solution11/src/org/apidesign/apifest08/currency/Computer.java@f6073056b9fe |
child 53 | 09d690bb97f6 |
permissions | -rw-r--r-- |
japod@6 | 1 |
package org.apidesign.apifest08.currency; |
japod@6 | 2 |
|
japod@6 | 3 |
/** |
japod@6 | 4 |
* Interface declaring method for computing conversion. |
japod@6 | 5 |
* |
japod@6 | 6 |
* Because of a vague definition of currency amount's type, |
japod@6 | 7 |
* the interface has a generic type. |
japod@6 | 8 |
* |
japod@6 | 9 |
* @author ked |
japod@6 | 10 |
* @see http://wiki.apidesign.org/wiki/APIDesignPatterns:ResponseReply |
japod@6 | 11 |
*/ |
japod@6 | 12 |
interface Computer<AmountType> { |
japod@6 | 13 |
|
japod@6 | 14 |
ComputerResponse<AmountType> compute(ComputerRequest<AmountType> request); |
japod@6 | 15 |
|
japod@6 | 16 |
/** |
japod@6 | 17 |
* |
japod@6 | 18 |
* @param <AmountType> |
japod@6 | 19 |
*/ |
japod@6 | 20 |
final class ComputerRequest<AmountType> { |
japod@6 | 21 |
|
japod@6 | 22 |
private AmountType input; |
japod@6 | 23 |
private AmountType inputCurrencyRatio; |
japod@6 | 24 |
private AmountType outputCurrencyRatio; |
japod@6 | 25 |
|
japod@6 | 26 |
AmountType getInput() { |
japod@6 | 27 |
return input; |
japod@6 | 28 |
} |
japod@6 | 29 |
|
japod@6 | 30 |
void setInput(AmountType input) { |
japod@6 | 31 |
this.input = input; |
japod@6 | 32 |
} |
japod@6 | 33 |
|
japod@6 | 34 |
AmountType getInputCurrencyRatio() { |
japod@6 | 35 |
return inputCurrencyRatio; |
japod@6 | 36 |
} |
japod@6 | 37 |
|
japod@6 | 38 |
void setInputCurrencyRatio(AmountType inputCurrencyRatio) { |
japod@6 | 39 |
this.inputCurrencyRatio = inputCurrencyRatio; |
japod@6 | 40 |
} |
japod@6 | 41 |
|
japod@6 | 42 |
AmountType getOutputCurrencyRatio() { |
japod@6 | 43 |
return outputCurrencyRatio; |
japod@6 | 44 |
} |
japod@6 | 45 |
|
japod@6 | 46 |
void setOutputCurrencyRatio(AmountType outputCurrencyRatio) { |
japod@6 | 47 |
this.outputCurrencyRatio = outputCurrencyRatio; |
japod@6 | 48 |
} |
japod@6 | 49 |
} |
japod@6 | 50 |
|
japod@6 | 51 |
final class ComputerResponse<AmountType> { |
japod@6 | 52 |
|
japod@6 | 53 |
private AmountType result; |
japod@6 | 54 |
|
japod@6 | 55 |
AmountType getResult() { |
japod@6 | 56 |
return result; |
japod@6 | 57 |
} |
japod@6 | 58 |
|
japod@6 | 59 |
void setResult(AmountType result) { |
japod@6 | 60 |
this.result = result; |
japod@6 | 61 |
} |
japod@6 | 62 |
} |
japod@6 | 63 |
|
japod@6 | 64 |
|
japod@6 | 65 |
} |