C#: interface inheritance getters/setters

后端 未结 4 729
一生所求
一生所求 2020-12-29 04:20

I have a set of interfaces which are used in close conjunction with particular mutable object.

Many users of the object only need the ability to read values from the

4条回答
  •  無奈伤痛
    2020-12-29 04:55

    Method hiding in an interface isn't nearly as grungy; I'd go with something like:

    interface IBasicProps {
       int Priority { get; }
       string Name {get;}
       //... whatever
    }
    
    interface IBasicPropsWriteable:IBasicProps  {
       new int Priority { get; set; }
       new string Name { get; set; }
       //... whatever
    }
    class Foo : IBasicPropsWriteable {
        public int Priority {get;set;}
        public string Name {get;set;}
    /* optional
        int IBasicProps.Priority {get {return Priority;}}
        string IBasicProps.Name {get {return Name;}}
    */
    }
    

提交回复
热议问题