How do you think about data access code like this:
public void AddCusotmer(Cusotmer customer)
{
//save customer into database
...
// save payment type
SavePaymentType(customer);
//save other data
...
}
private void SavePaymentType(Customer customer)
{
if(customer.PaymentType is XXXPayment)
{
var payment = customer.PaymentType as XXXPayment;
//save payment to XXXPayments table in db
...
}
else if(customer.PaymentType is YYYPayment)
{
var payment = customer.PaymentType as XXXPayment;
//save payment to YYYPayments table in db
...
}
...
}
Personally, I'm not feeling very well with codes like this (using "is" to detect type to decide what to do), but Robert Martin the author says it's OK for it's only in DAL, so a little bit violation of OCP is acceptable.
How do you think?