Business :
I have a payment system in which payment can be made using GiftCoupon, ClubMembershipCard, etc. One payment itself may have several payment components.
Grade :
I have a payment class. It has payment components such as GiftCouponPayment, ClubMembershipCardPayment, CashPayment and so on. Each type of component complies with the general IPaymentComponent interface. I implemented it using knowledge of existing types.
Questions
1) How to implement this function in an abstract way - without knowing that all types exist? This means that it should work for all types that implement the IPaymentComponent interface.
2) If this is not possible in LINQ to SQL, is this possible in the Entity Framework?
3) Is this an association / aggregation or composition when LINQ to SQL generates GiftCouponPayment objects inside the Payment object?
Note. I am using LINQ to SQL as an ORM. GiftCouponPayment and Payment are auto-generated classes, and these objects are created by ORM. I added extra functionality for these classes using partial classes.
Note. In the database, each PaymentComponent (e.g. GiftCouponPayment) has its own properties (e.g. CouponValue, CardValue, etc.). Therefore, the table for the hierarchy will not be good . We need separate tables. Is there a solution on this line?
Note. GiftCouponPayment already exists in the database prior to this payment. We need to identify the GiftCouponPayment object using the GiftCouponPaymentID provided by the client. We just need to update the PaymentID column in this table.
Leaking abstraction refers to any implemented abstraction designed to reduce (or hide) complexity when the underlying details are not completely hidden
LINQ to SQL Chart
REFERENCE :
C # CODE
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 = value; } } public int MyValue { get { return this.CouponValue; } set { this.CouponValue = value; } } public int GetEffectiveValue() { if (this.CouponNumber < 2000) { return 0; } return this.CouponValue; } } public partial class Payment { public List<IPaymentComponent> AllPaymentComponents() { List<IPaymentComponent> allPayComps = new List<IPaymentComponent>(); List<GiftCouponPayment> giftCouponPaymentList = new List<GiftCouponPayment>(); List<CashPayment> cashPaymentList = new List<CashPayment>(); foreach (GiftCouponPayment g in this.GiftCouponPayments) { giftCouponPaymentList.Add(g); allPayComps.Add(g); } foreach (CashPayment c in this.CashPayments) { cashPaymentList.Add(c); allPayComps.Add(c); } return allPayComps; } }