Another problem with properties
Marcin Kuszczak
aarti at interia.pl
Fri Aug 24 14:47:26 PDT 2007
Tristam MacDonald wrote:
> I hink what he was getting at is that properties are either functions or
> data members, when in reallity they should be neither. If they are to be
> useful, they need to be flexible enough that they can be either functions
> or a straight data member interchangeably, and that a property implemented
> as data should be overridable with function-type properties.
>
> How this would be implemented I have no idea, but I believe other
> languages have propper properties?
Yes. I was thinking more less about what you said. But I didn't describe
implementation, just use-cases.
>From implementation point of view maybe it would be possible to translate
automatically (by compiler) following definition:
interface I {
int x;
}
into:
interface I {
int x();
void x();
}
where necessary. In derived classes this translation could also happen if
there is declaration of the symbol x:
class A {
int x;
| // translation happens as x is same symbol as in interface.
\|/
int x() {
return _x;
}
void x(int x) {
_x=x;
}
}
It seems to solve my initial problem.
But above is just from top of my head - probably someone can propose better
solution...
--
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why I believe in Jesus - http://zapytaj.dlajezusa.pl (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------
More information about the Digitalmars-d
mailing list