How to refactor a verbose datatype? This morning I decided to write this question: https://stackoverflow.com/questions/11727571/are-there-problems-if-i-have-a-verbose-datatype/11727723#11727723

I don't really explain my scenario about how am I accesing through the nested dictionaries. I decided to have the default alias (IDictionary&lt;string, IDictionary&lt;Levels, IList&lt;Problem&gt;&gt;&gt;) but I'm thinking that's not a good option right now.

I'm gonna show some parts of my code:

ProblemBaseFactory

public abstract class ProblemBaseFactory : IProblemFactory
{
    private IDictionary&lt;string, IDictionary&lt;Levels, IList&lt;Problem&gt;&gt;&gt; problemDictionaryPackages;

    protected ProblemBaseFactory()
    {
        problemDictionaryPackages = new Dictionary&lt;string, IDictionary&lt;Levels, IList&lt;Problem&gt;&gt;&gt;();
    }

    protected IDictionary&lt;string, IDictionary&lt;Levels, IList&lt;Problem&gt;&gt;&gt; ProblemDictionaryPackages
    {
        get { return problemDictionaryPackages; }
    }

    public abstract IEnumerable&lt;Levels&gt; AvailableLevels(string packageName);
    public abstract IEnumerable&lt;Problem&gt; LoadProblems(ProblemFactoryProperties properties);
}


RuleProblemFactory

public abstract class RuleProblemFactory : ProblemBaseFactory
{
    private IDictionary&lt;string, IDictionary&lt;Levels, IList&lt;ProblemRule&gt;&gt;&gt; ruleDictionaryPackages;
    private IRuleAlgorithmSelector ruleAlgorithmSelector;
    private IList&lt;Problem&gt; temp;

    protected RuleProblemFactory()
        : this(new Dictionary&lt;string, IDictionary&lt;Levels, IList&lt;ProblemRule&gt;&gt;&gt;(), new SequentialRuleSelector())
    {
    }

    protected RuleProblemFactory(IRuleAlgorithmSelector ruleAlgorithmSelector)
        : this(new Dictionary&lt;string, IDictionary&lt;Levels, IList&lt;ProblemRule&gt;&gt;&gt;(), ruleAlgorithmSelector)
    {
    }

    protected RuleProblemFactory(IDictionary&lt;string, IDictionary&lt;Levels, IList&lt;ProblemRule&gt;&gt;&gt; ruleDictionary,
        IRuleAlgorithmSelector ruleAlgorithmSelector)
    {
        this.ruleDictionaryPackages = ruleDictionary;
        this.ruleAlgorithmSelector = ruleAlgorithmSelector;

        LoadBankOfRules();
    }

    protected IDictionary&lt;string, IDictionary&lt;Levels, IList&lt;ProblemRule&gt;&gt;&gt; RuleDictionaryPackages
    {
        get { return ruleDictionaryPackages; }
    }

    public override IEnumerable&lt;Problem&gt; LoadProblems(ProblemFactoryProperties properties)
    {
        // does exist the package name?
        if (!ProblemDictionaryPackages.ContainsKey(properties.NamePackage))
            throw new InvalidOperationException("namePackage");

        IDictionary&lt;Levels, IList&lt;Problem&gt;&gt; problemPackage = this.ProblemDictionaryPackages[properties.NamePackage];

        // does exist the list
        if (!problemPackage.ContainsKey(properties.Difficulty))
            problemPackage.Add(properties.Difficulty, new List&lt;Problem&gt;());

        temp = problemPackage[properties.Difficulty];

        if (temp.Count &gt;= properties.Quantity)
            return temp;
        else
            return GenerateProblems(properties);
    }

    private IEnumerable&lt;Problem&gt; GenerateProblems(ProblemFactoryProperties properties)
    {

        ruleAlgorithmSelector.Rules = ruleDictionaryPackages[properties.NamePackage][properties.Difficulty];

        ...
    }

    public override IEnumerable&lt;Levels&gt; AvailableLevels(string name)
    {
        return ruleDictionaryPackages[name].Keys;
    }
}


Sometimes I guess is difficult to readability. What do you recomend me to to mantain a better readability?
IDictionary&lt;string, IDictionary&lt;Levels, IList&lt;ProblemRule&gt;&gt;&gt; is difficult to understand and maintain. I don't know enough about your problem domain to give you reasonably sounding names for classes, but I'll try.

In your LoadProblems method, I see you set the IDictionary&lt;Levels, IList&lt;ProblemRule&gt;&gt; to a variable named problemPackage, so I would create a class ProblemPackage, containing a list of ProblemRules per Level (I would drop the 's' in Levels) and move the related logic there.

In ProblemBaseFactory you end up with a IDictionary&lt;string, ProblemPackage&gt;. ProblemPackage will have a IDictionary&lt;Level, ProblemRules&gt; and the class ProblemRules will be an easy wrapper around a IList&lt;ProblemRule&gt;.

If you try to delegate the work to these classes, the readability will almost certainly go up.