lundi 7 août 2017

C# refactoring a class with multiple dictionary properties

I have a class that looks like this:

public class AbstractReportFeeInfo
{
    public decimal TotalFee { get; set; }

    public Dictionary<long, decimal> TitleFeeDictionary { get; set; }  

    public Dictionary<VRAbstractInterfaceData, decimal> VRAbstractFeeDictionary { get; set; }

    public Dictionary<lkaData, decimal> LKAAbstractDictionary { get; set; }
}

I have a Billing class that processes the costs of a report type depending on what type it is (title, vrAbstract or LKA). These classes are very different from eachother.

Putting three dictionaries in this AbstractReportFeeInfo class is the only solution I could come up with...But, as of now, in other parts of my code, I will have to do conditional logic to determine which report type is being called and then call the appropriate dictionary in this AbstractReportFeeInfo class. Is there a more standard way to handle this type of scenario? I tried to make the AbstractReportFeeInfo class only have one dictionary with key - object and value - dictionay, like this:

public class AbstractReportFeeInfo
{
     public decimal TotalFee { get; set; }

     public Dictionary<object, decimal> dictionary{ get; set; } 
} 

But this doesn't really change much except now I still need conditional logic in other parts of my program, but then also need to explicitly cast to the appropriate data types.

Any ideas for how to design this is a more loosly coupled way?

Aucun commentaire:

Enregistrer un commentaire