digitalmars.D - feature request: interfaces for properties
- Henning Hasemann (27/27) Mar 06 2007 It would be nice if members would behave like properties, so one could e...
- BCS (4/34) Mar 06 2007 This is an interesting idea. To make it work however, the compiler would...
- Daniel Keep (11/47) Mar 06 2007 Not to mention that, at the moment, the members would suddenly stop
- Henning Hasemann (5/5) Mar 06 2007 Okay, I didnt see that would harm consistency of the programming languag...
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 -- v4sw7Yhw4ln0pr7Ock2/3ma7uLw5Xm0l6/7DGKi2e6t6ELNSTVXb7AHIMOen5a2Xs5Mr2g5ACPR hackerkey.com
Mar 06 2007
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. HenningThis 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.
Mar 06 2007
BCS wrote:Reply to Henning,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/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. HenningThis 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.
Mar 06 2007
Okay, I didnt see that would harm consistency of the programming language. I'd be interested in this template, though :-) Henning -- v4sw7Yhw4ln0pr7Ock2/3ma7uLw5Xm0l6/7DGKi2e6t6ELNSTVXb7AHIMOen5a2Xs5Mr2g5ACPR hackerkey.com
Mar 06 2007