6. 質問 http://sli.do/ #58755
アンケートhttp://u0u1.net/Urae
6
class Mathematic {
public Data sort(Data data){
switch(settings) {
case QUICK:
return quickSort(data);
case BUBBLE:
return bubbleSort(data);
default: ...
}
}
class Loan {
public double capital() {
if(expiry == null &&
maturity != null)
return ...;
if(expiry != null &&
maturity == null) {
...
}
class Mathematic {
Sorter sorter;
public Data sort(Data data){
return sorter.sort(data);
}
abstract class Sorter {
public abstract Data sort(Data);
class QuickSorter extends Sorter {
public Data sort(Data) { ... }
class Loan {
CapitalCalc capitalCalc;
public double capital(){
return capitalCalc.calc(this);
}
Interface CapitalCalc {
double calc(Loan l);
class TermCapital implements ...{
double calc(Loan l) { ... }
7. 質問 http://sli.do/ #58755
アンケートhttp://u0u1.net/Urae
例: オブジェクト指向デザインパターン Strategy
Context Strategy
algorithmInterface()
ConcreteStrategyA
algorithmInterface()
ConcreteStrategyB
algorithmInterface()
・・・
・・・
contextInterface()
解決
同期(文脈)
If there are hard-wiring line breaking algorithms, clients get
bigger and harder to maintain. Moreover it becomes difficult to
add new algorithms and vary existing ones…
適用可能性(問題、フォース)
Many related classes differ only in their behavior.
You need different variants of an algorithm…
結果
利点: families of algorithms , elimination of conditional statements…
欠点: Communication overhead…
E. Gamma, et al. “Design Patterns: Elements of Reusable Object-
Oriented Software,” Addison-Wesley, 1994.
7