English 中文(简体)
* 在某些情况下,Manager课程能够坚持其存在?
原标题:Can *Manager classes uphold their existence in some cases?

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);
    }
}
问题回答

您为什么认为需要将企业逻辑<>>><>>>><>tong>而不是纳入企业逻辑目标?

new OrderShredder().cancelOrder(order);

如何

order.cancel()

如果这一呼吁本身在<条码>中发出,实际上不小心。 OrderShredder(如果你真的需要的话)? http://pragprog.com/articles/tell-dont-ask” rel=“nofollow” 如何做事情,你不小心。

Run through the methods on the service/manager/whatever classes and have a look at the first argument s static type. Try to eliminate those classes by making the business logic object aware of themselves by actually assigning them behaviour.

点名: http://www.dotnetpro.de/articles/onlinearticle4046.aspx” rel=“nofollow”>article about weaselword 语言对点名问题适用(并非免费、高语言)。 我可以记住确切的细节,但论点是,以<代码>-er或-or结束的实务实体名义上填入了verbs,而通常应设法排除这些内容,而不仅仅是<代码>。 英文/法文。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签