开发者

How to relate Customer and Payment Details

开发者 https://www.devze.com 2022-12-21 03:28 出处:网络
I have a query rel开发者_运维问答ated to relation between objects. Scenario: Payment Details -

I have a query rel开发者_运维问答ated to relation between objects.

Scenario:

Payment Details - a. Credit Card b. Saving Account c. Cheque

Now, a customer should have any of the above payment detail before buying any product. How do i relate payment detail with customer.

Can any one explain with example...

Thanks in advance.


public interface IPaymentType 
{
  bool Pay(double amount);
}

public class CreditCardPType : IPaymentType
{
  double limit;
  // implement Pay()
}    
public class Cheque: IPaymentType
{
  int accountNumber;
  // implement Pay()
} 

public class Customer
{
    public IPaymentType paymentType { get; set; }
}


Customer customer = new Customer();
customer.paymentType = new CreditCardPType();


Not sure I get your question correctly, may be you can have a Customer class which has an attribtute "modeOfPayment" and this can be any of the possible options. Initialize this attribute in the constructor of the Customer class.

Alternatively may be keeping the payment details in a class like "Order" might be a better option. A customer can choose to pay for an order using credit card (say) and for some he can choose to pay by other means.


Add a Payment Detail property\field to your Customer Object. This will be the default payment mode when a customer buys a product.

0

精彩评论

暂无评论...
验证码 换一张
取 消