0
有价格范围(低,中,高)。不同产品类型的价格范围不同。需要Java设计模式建议。 (具有静态参数和方法的处理器)
我有一个处理程序类,其中包含所有价格范围,它可以确定产品的价格范围。
例如:
产品A,价钱:200,价格范围:50-300(MID)
产品B,价格:80,价格范围:70-120(高)
public class Handler {
// static priceRangeMap for Price ranges
public static void addPriceRange(PriceRange PriceRange){
//add price ranges to the priceRangeMap
//initialised when the application is started
}
public static String getClassificationForProduct(ProductData product) {
//determine classification for a product
}
}
public class ProductData {
public String getClassification() {
return Handler.getClassificationForProduct(this);
}
}
我不想在产品中存储价格范围,因为有很多产品具有相同的范围。
这是否是丑陋的解决方案?
Handler.getClassificationForProduct(this);
有没有更好的解决办法?
成分浮现在脑海。这不是一种真正的设计模式,但是如果您想要可重复使用的价格范围,请将其设为一个班级。 –
有没有什么方法/模式可以识别产品A是否与产品C相似,或者没有任何与其相关的属性变量? – charlypu
关于你的编辑,是的,你的Handler类有一个不好的代码异味,从它的静态方法开始。我认为你应该摆脱它。 –