digitalmars.D - interfaces and properties
- Roel Mathys (24/24) May 19 2004 interface Foo
- Vathix (18/42) May 19 2004 Properties are methods, not fields. Try this:
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 19 2004
"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, roelProperties 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); }
May 19 2004