Click here to Skip to main content
14,882,280 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have created the following:

<br />public interface ICalculatable<br />{<br />    DateTime FirstPaymentDate { get; }<br />    decimal MonthlyCompoundingRate { get; }<br />}<br /><br />public interface IBaseObject : ICalculatable<br />{<br />    string Identifier { get; }<br />   // Input Value<br />    DateTime FirstPaymentDate { get; set; }<br />   // Input Value<br />    decimal InterestRate { get; set; }<br />}<br /><br />public class BaseObject : IBaseObject<br />{<br />    ...<br />}<br />


I get a compiler error that need new to hide inherited member. I am trying to figure out if that is the correct thing or I need to use virtual/override/etc.. instead.

I will be accessing the BaseObject as ICalculatable in other code and the FirstPaymentDate properties should be the same value/source.

Thanks in advance.

Posted

in ICalculatable FirstPaymentDate just has a get

in IBaseObject (which implements ICalculatable) it has a get and a set, so the compiler is saying its not being implemented with the same signature, therefore you need to add the new keyword to hide the base FirstPaymentDate in ICalculatable

like so

<br />    public interface ICalculatable<br />    {<br />        DateTime FirstPaymentDate { get; }  <br />        decimal MonthlyCompoundingRate { get; }<br />    }<br />    <br />    public interface IBaseObject : ICalculatable<br />    {<br />        string Identifier { get; }<br />        new DateTime FirstPaymentDate { get; set; }<br />        decimal InterestRate { get; set; }<br />    }


EDIT
I have just reread your question and the above does not help does it [D'Oh]

Best way is to try it out in a demo project
   
Ware@Work wrote:
the FirstPaymentDate properties should be the same value/source.


IBaseObject has no value/source. Only the implementer does so this is not relevant to your scenario. It might be possible for the implementer to explicitly implement the two interfaces giving the implemented class different value/source. I have never tried it because, well it seems like a bad idea.

Also it is possible that there is different design than the two interfaces you are using that might better suit your needs. Perhaps reading Allen Holub discuss why Getters and Setters are Evil[^] will help you.


   



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900