Refactoring If clause I have a Customer class that has the code below. I can refactor the two if condition clauses into the Memebership class. Apart from that, I am wondering how I should refactor the if clause within the Benefits set property, without over-complicating thing.

Does any one of these below apply?

Patterns of refacotring if to subclass/strategy/state/polymorphism.

  public class Customer
    {

            public Membership Membership { get; private set; }
            public bool Hasbenefits { get; private set; }

            private int benefits;

            public int Benefits
            {
                get
                {
                    return benefits;
                }

                set
                {
                    if (Membership.Name == "MembershipA")
                    {
                        this.Hasbenefits = false;
                    }
                    else if (Membership.Name == "MembershipB")
                    {
                        this.Hasbenefits = true;
                        this.benefits = value * 4 + 2;
                    }
                    else
                    {
                        this.Hasbenefits = true;
                        this.benefits = value;
                    }
                }
            }
    }


Any advice would be very much appreciated!
Personally here's what I would do :

Use the Membership type to create derived class; this will remove the if chain completely.
Avoid side effects in setters; bad practice in my opinion.
Avoid using properties with private sets; bad practice in my opinion.

This results in the following code :

public abstract class Customer
{
     protected int benefits;

     public abstract void UpdateBenefits(int newBenefits);

     public bool HasBenefits()
     {
         return benefits != 0;
     }

     public int GetBenefits()
     {
         return benefits;
     }
 }

 public class MembershipACustomer : Customer
 {
     public override void UpdateBenefits(int newBenefits)
     {
     }
 }

 public class MembershipBCustomer : Customer
 {
     public override void UpdateBenefits(int newBenefits)
     {
         benefits = newBenefits * (4 + 2);
     }
 }

 public class MembershipSomethingElseCustomer : Customer
 {
     public override void UpdateBenefits(int newBenefits)
     {
         benefits = newBenefits;
     }
 }


IMO it would also be a good idea to make a hierarchy with a new Benefit class, instead of customers. You can pass the benefit type to the customer by DI and that way it is the Benefit class that is responsible for calculating the benefit, not the customer. This would respect SRP a little more.