我正在研究一个面向对象的设计问题。我将尝试专注于我感到困惑的部分,并用文字解释它,而不是提供代码。
I have a class called SalesPolicy that contains a List of TaxPolicy. TaxPolicy is an abstract class that represents a tax policy with name and tax rate as attributes. TaxPolicy contains an abstract method called accept. Concrete implementations of a TaxPolicy must implement the accept method and provide the logic for deciding when a TaxPolicy is applicable.
I have another class called SalesEngine. SalesEngine has a SalesPolicy and SalesPolicy is one of the parameters to the SalesEngine constructor. SalesEngine decides whether a TaxPolicy from a List of TaxPolicy in SalesPolicy is applicable for an item or not by calling the accept method and then calculates the tax accordingly. As explained earlier, SalesPolicy contains a single attribute which is a list of TaxPolicy and a method to add to the List.
我需要知道的是是否可以为 SalesEngine 类设置像 SalesPolicy 这样的参数。从可测试代码的角度来看,这有什么影响?