技术开发 频道

ABAP与设计模式之装饰者模式

【IT168 技术文章】

    首先,按照惯例,上例子程序的类图


    测试程序如下:

    REPORT ZBOBO_DP_003_RE .

    
*The class and interface for this program

    include zbobo_dp_003_if_cl.

    
*Reference data for drink definition

    data: dr_ref type ref to drink.

    
*Temp reference for decorator

    data:tdr type ref to drink.

    start
-of-selection.

    
*-------------------start decorate---------------*

    
* Narrowing cast

    
* Create darkroast object

    create object tdr type darkroast.

    
* Make dr_ref point to the object darkroast

    
* And this is the need to be decorated material

    dr_ref
= tdr.

    
* Use mocha to decorate object darkroast

    create object tdr type mocha

    exporting dr
= dr_ref. "This dr_ref is darkroast

    dr_ref
= tdr.

    
* Use soy to decorate object mocha&darkroast

    create object tdr type soy

    exporting dr
= dr_ref. "This dr_ref is mocha

    dr_ref
= tdr.

    
* Use whip to decorate object soy&mocha&darkroast

    create object tdr type whip

    exporting dr
= dr_ref. "This dr_ref is soy

    dr_ref
= tdr.

    
*-------------------end decorate---------------*

    
* Define data which used to display data

    data: ls type string,lf type f.

    
* Get description

    ls
= dr_ref->getdesc( ).

    
* Get cost

    lf
= dr_ref->cost( ).

    
* Display result

    write:
/ ls, ':$',lf decimals 2 exponent 0.

 

0
相关文章