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?
Let's say my callers want to interact with orders. Is it better to mix all kinds of methods into a single **Manager* class which will only delegate them to a proper class or let the caller use the proper class itself.
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);
And what about classes which do a bit more than a simple delegation (they use multiple delegations, execute them in a correct order or choose a next path based on some result from a delegate). Can these type of methods (like below) be in some kind of a manager class?
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);
}
}