May 19, 2004 interfaces and properties | ||||
|---|---|---|---|---|
| ||||
interface Foo
{
int good(); // here I must define a method
}
class Bar : Foo
{
int good() { return 15; }
/*
// does not satisfy interface Foo
int good;
this() { good = 13; }
*/
}
void main()
{
Bar b = new Bar();
printf("%d\n",b.good); // but I can access it as a property
}
too bad one can't define properties in an interface definition,
allowing properties but not allowing interfaces to define properties is a bit mmm ... I think it's not complete, I think properties are good, but something's amiss here
bye,
roel
| ||||
May 20, 2004 Re: interfaces and properties | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Roel Mathys | "Roel Mathys" <roel.mathys@yucom.be> wrote in message news:c8fknc$1t0d$1@digitaldaemon.com... > > interface Foo > { > int good(); // here I must define a method > } > > class Bar : Foo > { > int good() { return 15; } > /* > // does not satisfy interface Foo > int good; > this() { good = 13; } > */ > } > > void main() > { > Bar b = new Bar(); > > printf("%d\n",b.good); // but I can access it as a property > } > > too bad one can't define properties in an interface definition, allowing properties but not allowing interfaces to define properties is a bit mmm ... I think it's not complete, I think properties are good, but something's amiss here > > bye, > roel Properties are methods, not fields. Try this: interface Foo { int good(); } class Bar : Foo { int good() { return _good; } private int _good; this() { _good = 13; } } void main() { Bar b = new Bar(); printf("%d\n",b.good); } | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply