Feat. RQ: delegation alias
Frank Benoit
keinfarbton at nospam.xyz
Sun May 14 05:51:40 PDT 2006
In the Java Eclipse IDE, there is a refactoring called Delegate:
generate Methods to forward the call to a member variable. This is good
because you don't have to write so much, this is bad because there is so
much code, doing nothing :)
How about making this into the D language:
class A{
int getPrice(){ return 0; }
void print( int a ){}
void print( double a ){}
}
class B{
private A a;
alias a.getPrice getPrice;
/** Same like writing
int getPrice(){ return a.getPrice(); }
*/
alias a.print print;
/** Same like writing
void print( int a ){ a.print( a ); }
void print( double a ){ a.print( a ); }
*/
}
void main(){
B b = new B;
b.print( 1 );
}
The advantage is, changing the signature in A, automatically is visible
for users of B. Less code, more consistency.
More information about the Digitalmars-d
mailing list