Feat. RQ: delegation alias

Carlos noone at nowhere.com
Sun May 14 20:30:34 PDT 2006


Why wouldn't you make B inherit from A ?  Or make those methods a mixin ?


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.
> 



More information about the Digitalmars-d mailing list