feature request: interfaces for properties

BCS ao at pathlink.com
Tue Mar 6 09:13:25 PST 2007


Reply to Henning,

> It would be nice if members would behave like properties, so one could
> enforce
> them with interfaces.
> For example:
> interface IHasFoo {
> int foo();
> void foo(int);
> }
> // This class fullfills the interface
> class F1 : IHasFoo {
> int foo() { return 5; }
> void foo(int f) { };
> }
> // Would be nice to have this working too
> class F2 : IHasFoo {
> int foo;
> }
> If thats too strange to you, maybe one could instead allow members for
> interfaces like:
> 
> interface IHasFoo {
> int foo;
> }
> with F1, F2 fullfilling it.
> 
> I know that can be fixed with writing property methods around int foo,
> but that looks a bit rediculus and requires renaming of that member.
> 
> Henning
> 

This is an interesting idea. To make it work however, the compiler would 
in effect have to write the getters and setters for you (not hard but somewhat 
inconsistent), it would just amount to syntactic sugar.





More information about the Digitalmars-d mailing list