In this case, you could avoid the conditional logic by overloading the invoice method for different types.
在本例中,通过为不同类型重载invoice方法,您可以避免条件逻辑。
If you define an invoice method on a class, you have no way of knowing that some other user of that class won't define a different, incompatible method also named invoice.
如果您在类上定义invoice方法,则您没有办法知道该类的一些其他用户会不会定义不同的、不兼容的方法,还命名为invoice。
And this implementation is closed: After you compile the FulfillmentGenerator class, you can't extend the invoice method to new types without editing the source code and recompiling.
此实现是封闭的:在您编译FulfillmentGenerator类以后,在不编辑源代码和重新编译的情况下,您无法将invoice方法扩展到新的类型。
The product has a new field "Invoice Method": based on quantities ordered, based on quantities delivered (could be timesheets), based on time and material (reinvoice costs or expenses).
产品新增了“开票方式‘字段:可基于订单数量,送货数量(或是计工单),或者按时间和材料(重开票的成本或费用)
It defines a set of method names and their argument signatures, but no implementations. The invoice example might look like Listing 1.
它定义了一组方法名称和其参数签名,但是没有实现。
An insured shipping method (Priority Mail) is required for all international shipments valued at $100 or more. The cost of insurance will be added to your invoice. NO EXCEPTIONS.
漏掉了一件事,就是总金额超过100美元,好像强制要保险…会增加一点费用喔。
For HAWB data sent to Lufthansa Cargo using this method, we will invoice a fee of CNY 10.00 per HAWB.
以此方式向汉莎货运传输分单数据的货物,我们将依旧按每票分单10元计费。
For HAWB data sent to Lufthansa Cargo using this method, we will invoice a fee of CNY 10.00 per HAWB.
以此方式向汉莎货运传输分单数据的货物,我们将依旧按每票分单10元计费。
应用推荐