打印本文 打印本文 关闭窗口 关闭窗口
readonly vs. const [C#]
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2867  更新时间:2009/4/23 10:45:16  文章录入:mintao  责任编辑:mintao
{
    SuperVip,
    Vip,
    Normal
}


class Customer
{
    public Customer(string
 name, CustomerKind kind)
    
{
        m_Name =
 name;
        m_Kind =
 kind;
    }


    
private string m_Name;
    public string
 Name
    
{
        get { return m_Name; }

    }

    
private CustomerKind m_Kind;
    public
 CustomerKind Kind
    
{
        get { return m_Kind; }

    }

    
public override string ToString()
    
{
        return "Name: " + m_Name + "[" + m_Kind.ToString() + "]"
;
    }

}

 

  • 然而,当这种结合使用枚举和条件判断的代码阻碍了你进行更灵活的扩展,并有可能导致日后的维护成本增加,你可以代之以多态,使用Replace Conditional with Polymorphism来对代码进行重构。

上一页  [1] [2] [3] [4]  下一页

打印本文 打印本文 关闭窗口 关闭窗口