jeudi 7 décembre 2017

Replace if/else statement with pattern

In the code below, I'm trying to determine what the business date should be depending on if the month to date (mtd) indicator is true or if the previous 2 business date (btd) indicator is true.

Currently, if I come up with another indicator then I'll have to include another else if statement.

I've read that the approach to make this code easier to maintain is to use the Factory Design pattern. However, I'm not sure what steps to take in order to implement the pattern.

Here is the code:

    public static string GetBusDate(bool mtdIndicator, bool prev2BusDtInd)
    {
        string busDate = Helper.PreviousBusinessDate;

        if (mtdIndicator)
        {
            busDate = Helper.FOMBusDt;
        }
        else if (prev2BusDtInd)
        {
            busDate = Helper.Previous2BusinessDate;
        }

        return busDate;
    }

Aucun commentaire:

Enregistrer un commentaire