Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6118075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:23:38+00:00 2026-05-23T15:23:38+00:00

Ok, so C# has properties public int Prop {get;set;} I can put the getter

  • 0

Ok, so C# has properties

public int Prop {get;set;}

I can put the getter and the setter on separate interfaces like this:

public interface IRead
{ int AnInt { get; } }

public interface IWrite
{ int AnInt { set; } }

And then mix and match them like so:

public class WorkingClass : IRead, IWrite
{
    public int AnInt { get; set; }
}

Where it starts to go wrong is where I might have a base object.

public class BaseClass : IRead
{
    private int _anInt;

    public BaseClass(int anInt)
    { _anInt = anInt; }

    public virtual int AnInt
    { get { return _anInt; } }
}

I then want a derived class which can write as well.

public class Derived : BaseClass, IWrite //bits elided
{
    public override int AnInt
    {
        get { return base.AnInt; }
        set { throw new NotImplementedException(); } //<-- error
    }
}

Which of course doesn’t work.

This actually doesn’t come up that often. I prefer to have methods with change state and have properties read only. This is design 101 I guess, but as a contrived example, I’d have an Age property with just a get and then a method called IncreaseAge.

So with that all in mind. If you did want to have a mutable object with seperate read and write interfaces how would you do it?

I could do it in a Java-esque way with separate getter/setter methods on each interface. But that negates the benefits of properties + one of the cop programs will yell at me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:23:38+00:00Added an answer on May 23, 2026 at 3:23 pm

    You can have the base setter protected and have the derived class implement IWrite explicitly delegating to the base setter:

    public class BaseClass : IRead {
      public BaseClass(int anInt) { AnInt = anInt; }
    
      public int AnInt {
        get; protected set;
      }
    }
    
    public class Derived : BaseClass, IWrite {
      public Derived(int anInt) : base(anInt) { }
    
      int IWrite.AnInt {
        set { base.AnInt = value; }
      }
    }
    

    (The keyword base can even be omitted and the base property doesn’t need to be virtual.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like this: public class remoteStatusCounts : RemoteStatus { public int statusCount; public remoteStatusCounts(RemoteStatus r)
I have a usercontrol that has several public properties. These properties automatically show up
I have a user control that has a few public properties, one is an
I'm serializing to XML my class where one of properties has type List<string>. public
In my application I have a class which has properties of user-defined types like
I have an user view model that has the following properties: public User user;
Let's say I have a class which has three properties as below. public class
I encountered a class during my work that looks like this: public class MyObject
private List<T> newList; public List<T> NewList { get{return newList;} set{newList = value;} } I
I have an ASP.NET (.asmx) Web Service project that has a method like: public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.