是否有为类添加"选项"的模式?

Nes*_*cio 5 configuration design-patterns

我有一个类,我想允许几个(~20 +)配置选项.每个选项打开或关闭一项功能,或以其他方式改变操作.为了实现这一点,我使用默认值编写了一个单独的选项类.但是,我不得不在保护条件下丢弃我的代码来确定方法应该如何表现.我差不多完成了,但现在代码似乎闻到了.

是否有一个首选的方法/模式来实现这样的类?

编辑:更具体地说,我正在研究解析类.每个选项配置基本解析算法的互斥部分.例如,我的课程中有几个区域如下所示:

 if (this.Option.UseIdAttribute)
      attributeIDs = new Hashtable();
 else
      attributeIDs = null;


    public Element GetElementById(string id)
    {
        if (string.IsNullOrEmpty (id))
            throw new ArgumentNullException("id");

        if (attributeIDs == null)
            throw new Exception(ExceptionUseIdAttributeFalse);

        return attributeIDs[id.ToLower()] as Element;
    }
Run Code Online (Sandbox Code Playgroud)

Tho*_*ens 5

怎么样Decorator模式?它旨在为类动态添加行为.