c# - I have an existing interface (with properties) whats the best way to segregate read and write -


using c# have existing interface wish split read , write interfaces still keep original. best way?

i make 3 independent interfaces:

interface iexistingreadwrite{    int width {get; set;} }  interface iread{    int width {get;} }  interface iwrite{    int width {set;} } 

or make iexistingreadwrite inheret iread , iwrite, clearer other coders when @ iexistingreadwrite there segregated iread , iwrite interfaces available too...

interface iexistingreadwrite: iread, iwrite{    new int width {get; set;} }  interface iread{    int width {get;} }  interface iwrite{    int width {set;} } 

but i've had use 'new' on iexistingreadwrite shadow properties in iread , iwrite otherwise warnings ambiguity occur. shadowing not intention iexistingreadwrite 'pass work on' interfaces inhereted define new property (so there no opportunity there being seperate implementations each of seperate interfaces occuring). there better way.

it looks corak has best answer far... drop inhereting iwrite interface on iexistingreadwrite, solution looks like...

interface iexistingreadwrite : iread {     // use iwrite interface instead if require write only.      int width { get; set; } }  interface iread {     int width { get; } }  public interface iwrite {     int width {set; } } 

this gives ok behaviour. if require more security add adapter such as:

    internal class writeimpl : iwrite {     private iexistingreadwrite worker;     internal foowriteimpl(iexistingreadwrite i)     {         worker = i;     }      public string width     {         { throw new exception("dave cannot let that");}         set { worker.width = value; }     } } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -