@property and interfaces

Jonathan M Davis jmdavisprog at gmail.com
Tue Jun 29 03:32:16 PDT 2010

On Tuesday 29 June 2010 03:11:34 BLS wrote:
> Just wonder how to translate this C# snippet into D..
> //C#
>   public interface IBindingList   {
>      bool AllowEdit {
>        get;
>      }
> }
> //D2
> interface IBindingList {
> 	@property bool allowEdit();
> }
> Is this correct ? I think in C# AllowEdit() takes tare that you don't
> implement a setter. Seems to be impossible in D.
> Thanks Bjoern

Well, with the way that properties are implemented in D, I don't think that the 
getters and setters have any real relation with one another. If a getter is 
declared, you can use the property as an rvalue. If a setter is declared, you 
can use it as an lvalue. AFAIK, they don't really have any effect on each other 
and aren't really related. So, there certainly won't be any restriction on 
having a getter or setter in a class if an interface it implements declared only 
one. It's just that you'll only be able to use the one that's part of the 
interface if you're using a reference of the interface type rather than the 
implementing class.

And really, I see no point in it being more restrictive. The interface itself 
should be properly restrictive if you use it since it only declares one of the 
two. And if you're using the class directly, then what does what the interface 
does and doesn't have matter? You're using the class at that point, not the 

- Jonathan M Davis

More information about the Digitalmars-d-learn mailing list