ABAP设计模式实例-代理模式

背景

12306官网支持注册和订票操作,携程代理了12036,但是不支持注册功能

实例代码

"抽象接口
interface if_ticket.
  methods: register importing id type string,
    get_train_list importing from type string default '北京'.

endinterface.

"真实实现类-12306官网
class t12306 definition create public.
  public section.
    interfaces:if_ticket.
endclass.

class t12306 implementation.
  method if_ticket~register.
    write: / '用户' , id, '注册成功'.
  endmethod.
  method if_ticket~get_train_list.
    write:/  from ,'出发的所有列车'.
  endmethod.
endclass.

"代理类-携程
class ctrip definition create public.
  public section.
    interfaces:if_ticket.
    methods:set_current_location,
      constructor.

  private section.
    data:mo_t12306 type ref to t12306,
         mv_from   type string.
endclass.
class ctrip implementation.
  method constructor.
    mo_t12306 = new t12306( ).
  endmethod.
  method if_ticket~register.
    write:/ '携程不支持12306账户注册'.
  endmethod.
  method set_current_location.
    mv_from = '深圳'.
  endmethod.
  method if_ticket~get_train_list.
    me->set_current_location( ).
    mo_t12306->if_ticket~get_train_list( mv_from ).
  endmethod.
endclass.

start-of-selection.
  data(lo_booking_proxy) = new ctrip( ).
  lo_booking_proxy->if_ticket~register( '张三').
  lo_booking_proxy->if_ticket~get_train_list( ).

你可能感兴趣的:(设计模式,OO)