Код: Выделить всё
class Product {
double Price;
String name;
String category;
}
Код: Выделить всё
interface IFilterStrategy {
boolean apply(Product product);
}
class NameMatchStrategy implements IFilterStrategy {
String name;
public NameMatchStrategy(String name) {
this.name = name;
}
boolean apply(Product product) {
return product.getName().equals(name);
}
}
class PriceMatchStrategy implements IFilterStrategy {
double minVal;
double maxVal;
public StringMatchStrategy(double minVal, double maxVal) {
this.minVal = minVal;
this.maxVal = maxVal;
}
boolean apply(Product product) {
return product.getPrice() >= minVal && product.getPrice()
Подробнее здесь: [url]https://stackoverflow.com/questions/78296622/strategy-pattern-to-filter-objects-how-to-compose-them[/url]
Мобильная версия