IdentityIdentify the hidden business concept
class ProductFactory { private static readonly Dictionary<bool, Dictionary<bool, Func<IProduct>>> _products = new Dictionary<bool, Dictionary<bool, Func<IProduct>>>(); static ProductFactory() { _products.Add(false, new Dictionary<bool, Func<IProduct>> { { true, () => new ProductSingleWithChildren() }, { false, () => new ProductSingle() } }); _products.Add(true, new Dictionary<bool, Func<IProduct>> { { true, () => new ProductMarriedWithChildren() }, { false, () => new ProductMarried() } }); } public IProduct GetProduct(bool isMarried, bool hasChildren) { return _products[isMarried][hasChildren](); } } You'll notice in the end we not only got rid of the duplicate if condition, there are in fact ZERO if statements in the whole solution!!! :) Pretty neat, and will get you a low cyclomatic complexity score and a nice clean CPU pipeline. Plus much more readable code.
Then again, we just wrote a LOT more lines of code than the original example. So, depending on context, maybe the nested if statements would be better, in certain cases, e.g. the combination of the flags is arbitrary or doesn't map to a logical concept within the business problem, or the extra readability isn't necessary for a certain small problem. It's up to you, of course.