Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

I'm asked to refactor my component code to support A/B Testing.

What is the better approach:
1) Pass a boolean value to the methods and check for that flag inside the method body?

method(flag abTest):    
       // Do 'A' logic
       // Do 'B' logic

2) Create dedicated methods for each version?

share|improve this question
You might want to have a look at the concept of Feature Toggle : –  guillaume31 Jun 26 '13 at 13:37

1 Answer 1

You should look into the Strategy Pattern. It allows you to swap out the behavior of a function or object on the fly by using interfaces. You specify how a method will be called, then have two or more versions that implement that interface. Then, you don't care about which one you're using in the code except upon initialization.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.