If I have the following Interface structure;
public interface IPaymentTypeBase
{
void PayNow();
double Amount { get; set; }
}
public interface IPaymentTypePayPal : IPaymentTypeBase
{
string UserName { get; set; }
string Password { get; set; }
}
public interface IPaymentMethod<T>
{
}
Then I have the following classes;
public class PaymentTypePayPal : IPaymentTypePayPal
{
public string UserName { get; set; }
public string Password { get; set; }
public void PayNow()
{
throw new NotImplementedException();
}
}
public class PaymentMethod<T> : IPaymentMethod<T> where T : IPaymentTypeBase
{
}
Then in my web application I have this;
IPaymentMethod<IPaymentTypePayPal> payer = (IPaymentMethod<IPaymentTypePayPal>) new PaymentMethod<PaymentTypePayPal>();
I’d now like to call payer.PayNow(); but I’m just getting lost in interfaces etc and can’t seem to make this work.
I believe this is a simple thing but am just missing the point entierly.
Can anyone help?
Edit
The intention here is to have a set of interface such as PayPal, Voucher, CreditCard all of which do their own payment gateway type of stuff.
So I’d like to instantiate a class that takes the Payment Type as an interface and call that interfaces PayNow method.
payer is of type
IPaymentMethod<IPaymentTypePayPal>.But
IPaymentMethod<T>is defined asTherefore, it has no methods and you can’t call
PayNow()on it.The same is true for
PaymentMethod<T>, so you can’t call any method on an instance ofPaymentMethod<PaymentTypePaypal>either.Maybe you can explain a little more what your intention is.