feature request: interfaces for properties

Daniel Keep daniel.keep.lists at gmail.com
Tue Mar 6 10:55:49 PST 2007



BCS wrote:
> 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.

Not to mention that, at the moment, the members would suddenly stop
being valid lvalues.

That reminds me; I need to finish that template for generating getters
and setters :P

	-- Daniel

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list