Easy way to implement interface properties?

Frustrated c1514843 at drdrb.com
Tue Dec 31 16:58:35 PST 2013


On Wednesday, 1 January 2014 at 00:53:53 UTC, Namespace wrote:
> On Wednesday, 1 January 2014 at 00:48:13 UTC, Frustrated wrote:
>> Is there an easy way to implement properties of an interface 
>> within a class instead of having to duplicate almost the exact 
>> same code with generic properties?
>>
>> interface A
>> {
>>    @property int data() { return m_data; } // read property
>>  @property int data(int value) { return m_data = value; } // 
>> write property
>>
>> }
>
> Without access to some members, yes: make the methods final.
> With (as in your case): Only with an abstract class or with a 
> mixin template.

This was somehow posted before I finished.

Final is not the way I want to do it(I'll still have to write 
code with it, but that's besides the point as it adds extra work 
that is not necessary).

I simply need a way to build up the functionality of the code 
instead of having to write a bunch of code that will change 
anyways. One can't use interfaces directly(since they generally 
contain no code) and one can't build up an interface full of code 
since that defeats the purpose(just use classes in the first 
place).


I just don't see any reason(and there is none, except to waste 
time, or for love of typing) to implement default generic 
behavior over and over when it can *easily* be automated.


More information about the Digitalmars-d-learn mailing list