I ve recently read that calling classes **Manager* is a bad thing due to their not exact name and a possibility that they might become god objects. However, is it a good practice to provide Manager as a wrapper for multiple different methods from different classes dealing with the same business object?
我要说的是,我的人希望与命令互动。 最好把各种方法混为一谈**.Manager* ,这只能把他们交给适当的班级,或让打电话者使用适当的班级。
So
OrderManager orderManager = new OrderManager();
orderManager.cancelOrder(order); -> delegates to OrderShredder
orderManager.sendOrder(order, destination); -> delegates to OrderSender
or
new OrderShredder().cancelOrder(order);
new OrderSender().sendOrder(order, destination);
哪类比简单代表团多(使用多个代表团,按正确的顺序执行,或根据某个代表的某些结果选择下一个途径)。 这些类型的方法(如下文)是否属于某种管理人员类别?
public Order makeOrder(List<Product> products, Customer customer) {
BigDecimal orderValue = this.productPriceCalculator.calculatePrice(products, customer);
Order order = this.orderCreator.createOrder(products, customer, orderValue);
boolean orderIsOk = this.orderValidator.validate(order);
if (orderIsOk) {
OrderStatistics orderStatistics = this.orderEvaluator.evaluate(order);
boolean orderValueIsBigEnough = orderStatistics.isValueBigEnough();
if (orderValueIsBigEnough) {
this.orderSender.sendInformationAboutOrderSomewhere(order, orderStatistics);
}
}
else {
throw OrderNotOkException(order);
}
return order;
}
public void cancelOrders(Customer customer) {
List<Order> customerOrders = this.ordersStorage.getOrders(customer);
for (Order order : customerOrders) {
orderShredder.cancelOrder(order);
}
}