interface FilterStrategy {
public void filter();
}
class OldProductsStrategy implements FilterStrategy {
public filter();
}
class NewProductsStrategy implements FilterStrategy {
public filter();
}
class ProductsFilterStrategy {
public getFilter(a) {
if(a) {
return new NewProductsStrategy();
} else {
return new OldProductsStrategy();
}
}
class Client {
new ProductsFilterStrategy().getFilter(true).filter();
}
는 전략 패턴의 전략 구현 부분의 선택을 위임 된 전략의 잘못된 사용을 다음인가?
'getFilter'에 전달할 값이 런타임에 결정되면 - 그걸로 어떤 문제도 볼 수 없습니다. 그렇지 않은 경우 잠재적으로 약간 중복 될 수 있습니다. – Bilkokuya