如何從子類的方法訪問超類的方法?訪問超類的成員函數
這裏是一個能說明問題的例子: 比方說,我們有兩個班
class parent definition.
public section.
methods f.
endclass.
class child definition inheriting from parent.
public section.
methods f redefinition.
methods g.
endclass.
現在,在g
實現中,我們要調用超類的實現的f
相似以下語法錯誤的片段
class child implementation.
method g.
super->f(). "forbidden: super-> can only be used to call the previous implementation of the same method
endmethod.
endclass.
正如評論指出,這是不可能使用super->
。你能幫我嗎?
一些google搜索後,有人建議的parent->f
執行復制到child->g
這是真的做到這一點的唯一途徑?
實際使用情況
@vwegert問爲什麼f
首先被重新定義。在我的真實使用案例中,parent
是一個視圖,而child
是它的擴展。 child->f
是一個應該觸發彈出窗口的事件處理程序。 child
當彈出窗口以g
的呼叫形式關閉時收到回叫。如果調用g
,則應調用原始實現parent->f
。
爲什麼你首先重新定義方法......? – vwegert
@vwegert我已經將實際用例添加到問題中,但我相信,一般問題也應該得到答案。 – niklasfi