次の状況をモデル化するのに助けが必要です。
金融商品には必ず価格があります。ただし、一部の金融商品 (むしろ特定の種類の) には、価格に (とりわけ) 依存する属性である「クリーン」価格と呼ばれるものもあります。この場合、価格は「ダーティ」価格とも呼ばれます。価格 (またはダーティ プライス) とクリーン プライスの両方を計算する計算サービスがあります。その状況を概念的にモデル化するにはどうすればよいでしょうか?
私は2つの選択肢を検討しました:
FinancialInstrument には価格があります
FinancialInstrument + price: Price
Price は、DirtyPrice と CleanPrice の 2 つの派生クラスを持つスーパータイプです。CleanPrice は DirtyPrice に依存します
CleanPrice + dirty: DirtyPrice
次に、Calculator サービスは FinancialInstrument の価格を計算します。
CalculatorService + compute_price(FinancialInstrument, ...): Price
FinancialInstrument は、次の 2 つの派生を持つスーパータイプです。PlainFinancialInstrument (価格属性のみを持つ) と、クリーン価格とダーティ価格の両方を持つ CleanPriceFinancialInstrument です。
FinancialInstrument + price: double PlainFinancialInstrument CleanPriceFinancialInstrument + clean_price: double
次に、Calculator サービスには、PlainSecurity の価格または CleanPriceSecurities のクリーン価格とダーティ価格を計算する 2 つのメソッドがあります。
CalculatorService + compute_price(PlainFinancialInstrument, ...): double + compute_price(CleanPriceFinancialInstrument, ...): pair<double, double>
両方の選択肢のトレードオフは何ですか? 他の選択肢はありますか?
ありがとう。