背景
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( ).