业务:
我有一个支付系统,可以通过GiftCoupon,ClubMembershipCard等支付.一个支付本身可以有多个支付组件
课程:
我有一个付款类.它有支付组件,如GiftCouponPayment,ClubMembershipCardPayment,CashPayment等.每种组件类型都满足通用接口IPaymentComponent.我使用有关现有类型的知识实现了它.
问题
1)如何以抽象的方式实现这个功能- 不知道存在哪些类型?这意味着它需要适用于实现IPaymentComponent接口的所有类型.
2)如果在LINQ to SQL中无法实现它,是否可以在Entity Framework中实现?
3)当LINQ to SQL在Payment对象中生成GiftCouponPayment实体时,它是关联/聚合还是组合?
注意:我使用LINQ to SQL作为ORM.GiftCouponPayment和Payment是自动生成的类,这些对象由ORM创建.我通过使用部分类为这些类添加了更多功能.
注意:在数据库中,每个PaymentComponent(例如GiftCouponPayment)都有自己的属性(例如CouponValue,CardValue等).因此,按层次结构表将不会很好.我们需要单独的表格.那条线路有解决方案吗?
注意:此付款之前,数据库中已存在GiftCouponPayment.我们需要使用客户提供的GiftCouponPaymentID来识别GiftCouponPayment对象.我们只需要更新此表中的PaymentID列.
泄漏抽象是指任何已实现的抽象,旨在减少(或隐藏)复杂性,其中底层细节未被完全隐藏
LINQ to SQL Diagram

参考:
C#代码
public interface IPaymentComponent
{
int MyID { get; set; }
int MyValue { get; set; }
int GetEffectiveValue();
}
public partial class GiftCouponPayment : IPaymentComponent
{
public int MyID
{
get
{
return this.GiftCouponPaymentID;
}
set
{
this.GiftCouponPaymentID = …Run Code Online (Sandbox Code Playgroud)