9
有時,當使用策略模式時,我發現某些算法實現不需要相同的參數列表。策略模式中的變化參數
例如
public interface Strategy{
public void algorithm(int num);
}
public class StrategyImpl1 implements Strategy{
public void algorithm(int num){
//num is needed in this implementation to run algorithm
}
}
public class StrategyImpl2 implements Strategy{
public void algorithm(int num){
//num is not needed in this implementation to run algorithm but because im using same
strategy interface I need to pass in parameter
}
}
有沒有我應該使用不同的設計模式?