Reputation: 441
These types of methods have always bothered me. Without digging through the code, I have no idea what the key or sub-value is supposed to be in this dictionary. I've done this myself about a thousand times, I'm sure. But it has always bothered me because it lacks so much information.
IDictionary<int,HashSet<int>> GetExportedCharges()
{
...
}
void GetVisitStatuses(IDictionary<int,HashSet<int>> exportedCharges)
{
...
}
Having the material in a dictionary makes sense, but all of the IDictionary methods have very abstract parameters. I suppose I could create a new class, implement IDictionary, and rename all of the parameters. It just seems like overkill. Makes be wish c# had a 'typdef' directive.
How do you avoid returning dictionaries like this? Or do you avoid this at all?
Upvotes: 4
Views: 273
Reputation: 2330
Personally I don't avoid returning dictionaries.
I agree, having only method signature it all looks very vague. So my rule is to ALWAYS write comments in a style "Dictionary (logical description of the keys) - (logical description of values)". And to hope that I will not need to use something horrible like
Dictionary<SomeType, <Dictionary<...>>
Upvotes: 0
Reputation: 437604
There is a very simple solution that you might find adequate:
public class IdToSetOfWidgetNumbersMap : Dictionary<int,HashSet<int>> { }
Advantages:
IdToSetOfWidgetNumbersMap
doesn't leave many questions openDictionary
if you preferDisadvantage:
Upvotes: 9