tags:

views:

65

answers:

3

Hello Everybody,

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.

A: 

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.

sateesh
+2  A: 
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();
Asad Butt
This good for Credit Card Payment Type, what else in case of cheque. Both Credit Card and Cheque have few different attributes.
Nirajan Singh
derive the other two classes from IPaymentType interface
Asad Butt
define behaviour like Pay() or something in interface. Keep attributes seperate to your classes. Have made editions
Asad Butt
But our interface has only the common attributes for both and Customer and Payment Type is related through interface. so i am not able to get all the attributes of Cheque.
Nirajan Singh
why are you putting attributes in interface ?
Asad Butt
+2  A: 

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

Jojo Sardez