Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8784683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:09:34+00:00 2026-06-13T21:09:34+00:00

[EDIT] I organize my question again, Models for parameter public class PaymentModel { …

  • 0

[EDIT]

I organize my question again,

Models for parameter

public class PaymentModel
{   
    ... 
}

public class CCPaymentModel : PaymentModel
{
    ...
}

public class PaypalPaymentModel : PaymentModel
{
    ...
}

public class GooglePaymentModel : PaymentModel
{
    ...
}    

Interface class

public interface IPayment<T> where T : PaymentModel
{
    ...
}

Models (get inheritance from IPayment),

public class SagePayment
    : IPayment<CreditCardPaymentInfo>
{
    public void MakePayment( CreditCardPaymentInfo creditCardPaymentInfo ) {
        // ...
    }

    public void MakeRefund( CreditCardPaymentInfo creditCardPaymentInfo ) {
        // ...
    }
}

public class GooglePayment
    : IPayment<GooglePaymentModel>
{
    public void MakePayment( GooglePaymentModel paymentInfo ) {
        // ...
    }

    public void MakeRefund( GooglePaymentModel paymentInfo ) {
        // ...
    }
}

public class PaypalPayment
    : IPayment<PayPalPaymentModel>
{...}

Controller (Create instance)

IPayment<???> paymentProcess; // //Error    1   Using the generic type 'com.WebUI.Models.IPayment<T>' requires 1 type arguments

if (Regex.IsMatch(paytype, "^Credit Card"))
{
    paymentProcess = new SagePayment(); // it need CCPaymentModel type parameter
}
else if (Regex.IsMatch(paytype, "^PayPal"))
{
    paymentProcess = new PayPalPayment(); // it need PaypalPaymentModel type parameter
}
else if (Regex.IsMatch(paytype, "^Google"))
{
    paymentProcess = new GooglePayment(); // it need GooglePaymentModel type parameter
}

[EDIT]

public void Charge(string paytype,orderNo){

    IPayment<???> paymentProcess; // //Error    1   Using the generic type 'com.WebUI.Models.IPayment<T>' requires 1 type arguments
    Object payinfo;

    if (Regex.IsMatch(paytype, "^Credit Card"))
    {
        paymentProcess = new SagePayment(); // <== Error, Can not casting
        payinfo = getPaymentInfo(paytype, orderNo); // it return CCPaymentModel type object
    }
    else if (Regex.IsMatch(paytype, "^PayPal"))
    {
        paymentProcess = new PayPalPayment();
        payinfo = getPaymentInfo(paytype, orderNo); // it return PaypalPaymentModel type object
    }
    else if (Regex.IsMatch(paytype, "^Google"))
    {
        paymentProcess = new GooglePayment(); // it return GooglePaymentModel type object
        payinfo = getPaymentInfo(paytype, orderNo); 
    }

    paymentProcess.MakePayment(payinfo);
}

enter image description here

[EDIT #2]

With this,

public interface IPayment {
}

public interface IPayment<T> : IPayment where T : PaymentModel
{
    void MakePayment(string pickno);
    void makeRefund(T refundInfo);
}

I got an error, Error 1 ‘com.WebUI.Models.IPayment’ does not contain a definition for ‘MakePayment’ and no extension method ‘MakePayment’ accepting a first argument of type ‘Ecom.WebUI.Models.IPayment’ could be found (are you missing a using directive or an assembly reference?)

So, to avoid that error, I move MakePayment method to upper interface class,

public interface IPayment {
    void MakePayment(string pickno);
}

public interface IPayment<T> : IPayment where T : PaymentModel
{
    void makeRefund(T refundInfo);
}

Now, the error is gone, BUT how should I do in makeRefund case?
I can not move to upper interface class because I need generic type parameter.

Could you help me a little more please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:09:36+00:00Added an answer on June 13, 2026 at 9:09 pm

    You would want to have another IPayment interface without the generics from which IPayment inherits from. That is:

    public interface IPayment
    {
    
    }
    
    public interface IPayment<T> : IPayment where T : PaymentModel
    {
    
    }
    

    EDIT: If you really don’t want to have an IPayment base interface, then you’d have to treat them as type object:

    object paymentProcess;
    
    if (Regex.IsMatch(paytype, "^Credit Card"))
    {
        paymentProcess = new SagePayment();
    }
    else if (Regex.IsMatch(paytype, "^PayPal"))
    {
        paymentProcess = new PayPalPayment();
    }
    else if (Regex.IsMatch(paytype, "^Google"))
    {
        paymentProcess = new GooglePayment();
    }
    

    But that might cost you later; regardless you’re going to have to cast to work with the specific implementation types. You’re really best using a base interface. You may even use it in a nice way:

    public interface IPayment
    {
        PaymentModel Payment { get; }
    }
    

    So you can reference and use the PaymentModel without knowing that it’s actually a GooglePaymentModel specifically.

    EDIT: Based on your comment, you might have something like:

    public interface IPayment
    {
        void MakePayment(string pickno);
    }
    
    public interface IPayment<T> : IPayment where T : PaymentModel
    {
        void MakeRefund(T refundInfo);
    }
    

    You could even have a non-generic MakeRefund version typed against PaymentModel so your calling code might not care if it’s a GooglePayment or not. (but that could cause other issues if they pass a PayPalPayment, so that’s up to you)

    EDIT: Based on your latest code, you’ll want something like this:

    public interface IPayment
    {
    
    }
    
    public interface IPayment<T> : IPayment where T : PaymentModel
    {
        void MakePayment(T paymentInfo);
        void MakeRefund(T paymentInfo);
    }
    

    Your controller/factory would look like:

    //not sure on the exact signature since you didn't provide it
    public IPayment CreatePayment(string paytype)
    {
        IPayment paymentProcess = null;
    
        if (Regex.IsMatch(paytype, "^Credit Card"))
        {
            paymentProcess = new SagePayment();
        }
        else if (Regex.IsMatch(paytype, "^PayPal"))
        {
            paymentProcess = new PayPalPayment();
        }
        else if (Regex.IsMatch(paytype, "^Google"))
        {
            paymentProcess = new GooglePayment();
        }
    
        return paymentProcess
    }
    

    Your usage code would somewhere have to cast it to the known payment type to use:

    IPayment untypedPayment = Factory.CreatePayment("PayPal");
    IPayment<PayPalPaymentModel> typedPayment = (IPayment<PayPalPaymentModel>)untypedPayment;
    typedPayment.MakePayment(new PayPalPaymentModel());
    
    //or alternatively
    IPayment untypedPayment = Factory.CreatePayment("PayPal");  
    PayPalPayment typedPayment = (PayPalPayment)untypedPayment;
    typedPayment.MakeRefund(new PayPalPaymentModel());
    

    EDIT: Based on your latest edits, this is what you want. Drive your base IPayment calls against a PaymentModel. Then in the specific implementations you can cast or type-check at runtime:

    public interface IPayment
    {
        void MakePayment(PaymentModel paymentInfo);
        void MakeRefund(PaymentModel paymentInfo);
    }
    
    public interface IPayment<T> : IPayment where T : PaymentModel
    {
    
    }
    
    public class GooglePayment
        : IPayment<GooglePaymentModel>
    {
        public void MakePayment(PaymentModel paymentInfo) {
        GooglePaymentModel googlePayment = (GooglePaymentModel)paymentInfo;
        // ...
        }
    
        public void MakeRefund(PaymentModel paymentInfo) {
        GooglePaymentModel googlePayment = (GooglePaymentModel)paymentInfo;
        // ...
        }
    }
    

    Then your Controller:

    public void Charge(string paytype,orderNo){
    
        IPayment paymentProcess = null;
        PaymentModel payinfo = null;
    
        if (Regex.IsMatch(paytype, "^Credit Card"))
        {
            paymentProcess = new SagePayment();
            payinfo = getPaymentInfo(paytype, orderNo);
        }
        else if (Regex.IsMatch(paytype, "^PayPal"))
        {
            paymentProcess = new PayPalPayment();
            payinfo = getPaymentInfo(paytype, orderNo);
        }
        else if (Regex.IsMatch(paytype, "^Google"))
        {
            paymentProcess = new GooglePayment();
            payinfo = getPaymentInfo(paytype, orderNo); 
        }
    
        paymentProcess.MakePayment(payinfo);
    }
    
    public PaymentModel getPaymentInfo(string paytype,orderNo)
    {
        //return some payment model
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
Edit (updated question) I have a simple C program: // it is not important
EDIT: Simple version of the question: I want to create server variables in the
This question can be related to any MVC Framework. How do you organize your
again a total newbie question from me about Haskell, and Leskah. (First, a subjective
edit: Ok, to put this in a question, I'm asking for possible ways I
This is a followup question to my question , that was left unanswered EDIT
Edit : Of the several extremely generous and helpful responses this question has already
EDIT: I was an idiot. I simply had an image that was vertically long,
EDIT: See my answer below--> I am wanting to have a view that when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.