Nirajan Singh
Nirajan Singh

Reputation: 2885

How to relate Customer and Payment Details

I have a query related 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.

Upvotes: 2

Views: 570

Answers (3)

Asad
Asad

Reputation: 21928

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();

Upvotes: 3

Jojo Sardez
Jojo Sardez

Reputation: 8568

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

Upvotes: 0

sateesh
sateesh

Reputation: 28693

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.

Upvotes: 0

Related Questions