mercredi 1 décembre 2021

How do I have a method return one of almost the same classes case to case?

I am integrating a new payment way into our service project. I coded everything. Now I want it to be convenient to Solid principles. However, I am stuck how to overcome a case. Our service already have a method that called GetPaymentProfile and returns a class named PaymentProfile. After Integration I had to add a new PaymentProfile and method, because this new class has a new property.

Because of this, I obtained two class and two methods. Every step coded twice needlessly. I just want you to advise how I can do to overcome this.

preexisting method a class:

public class PaymentProfile
{
    public String Property1 = "";
    public String Property2 = "";
    public String Property3 = "";
    public String Property4 = "";
}

public PaymentProfile GetPaymentProfile(long aTicketType) {..}

class and method obtained after integration

public class PayCorePaymentProfile
{
    public String Property1 = "";
    public String Property2 = "";
    public String Property3 = "";
    public String Property4 = "";
    public String Property5 = "";
}

enter code here public PayCorePaymentProfile GetPayCorePaymentProfile(long aTicketType) {..}

What I thought

Creating a base class and then binding all sub-class with this base class, but I think it is not suitable for this case. Because I would return this base class without new property.

If I put everything in this base class, the old model has a new property needlessly.

*sorry for grammar rules and mistakes

Aucun commentaire:

Enregistrer un commentaire