Feat. RQ: delegation alias
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Sun May 14 11:04:15 PDT 2006
Frank Benoit wrote:
> 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.
>
I'll second this one. Its a natural evolution of the current use of alias to do method
inheritance when overloading.
-- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list