C#: interface inheritance getters/setters

后端 未结 4 724
一生所求
一生所求 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:37

    If your goal is to make it clearer when reading vs. writing is allowed, then I would use separate getter and setter methods rather than properties.

    interface IBasicProps {
       int GetPriority();
       string GetName();
       //... whatever
    }
    
    interface IBasicPropsWriteable:IBasicProps  {
       void SetPriority(int priority);
       void SetName(string name);
       //... whatever
    }
    

提交回复
热议问题