Tôi muốn gọi phương thức PL/SQL đã ghi đè. Dưới đây là ví dụ:Cách gọi phương thức siêu đối tượng Oracle PL/SQL
-- super class
create or replace type test as object
(
n number,
member procedure proc(SELF in out nocopy test, s varchar2)
)
alter type test not final
/
create or replace type body test is
member procedure proc(SELF in out nocopy test, s varchar2) is
begin
dbms_output.put_line('test1: n='||nvl(self.n, 'null')||' s='||s);
self.n := to_number(s);
end;
end;
/
-- derived class
create or replace type test2 under test
(
overriding member procedure proc(SELF in out nocopy test2, s varchar2)
)
/
Bây giờ tôi muốn gọi phiên bản kế thừa của phương pháp proc
. Khi tôi cố gắng làm một diễn viên rõ ràng như treat(self as test).proc(s);
nó sẽ không biên dịch vì PLS-00.363: biểu hiện 'SYS_TREAT' không thể được sử dụng như một mục tiêu chuyển nhượng
Cơ thể loại biên dịch khi tôi sử dụng một biến địa phương:
create or replace type body test2 is
overriding member procedure proc(SELF in out nocopy test2, s varchar2) is
O test;
begin
O := treat(self as test);
O.proc(s);
end;
end;
/
Nhưng khi tôi chạy ví dụ của tôi như thế này
declare
obj test2;
begin
obj := test2(0);
obj.proc('1');
end;
... nó ném ORA-21.780: số lượng tối đa những khoảng thời gian đối tượng vượt quá.
Có cách nào để gọi kiểm tra :: proc (không serialize/deserializing) không?
Và ... sau khi proc đã được gọi, làm thế nào có thể thay đổi bất kỳ thuộc tính (cụ thể là n
) được phản ánh trong obj
?
Cập nhật (Cảm ơn, tbone):
tôi đã thay đổi việc tổ chức các phương pháp của tôi sử dụng phương pháp mẫu ('trước' và 'sau khi'). Tôi thêm chúng bất cứ khi nào tôi cần phải mở rộng một phương pháp.
create or replace type test as object
(
n number,
member procedure proc (SELF in out nocopy test, s varchar2),
member procedure afterProc (SELF in out nocopy test, s varchar2)
member procedure beforeProc(SELF in out nocopy test, s varchar2),
)
not final
/
create or replace type body test is
member procedure proc(SELF in out nocopy test, s varchar2) is
begin
beforeProc(s);
dbms_output.put_line('test1: n='||nvl(n, 'null')||' s='||s);
n := to_number(s);
afterProc(s);
end;
member procedure afterProc (SELF in out nocopy test, s varchar2) is begin null; end;
member procedure beforeProc(SELF in out nocopy test, s varchar2) is begin null; end;
end;
/
từ tài liệu có vẻ như TREAT được sử dụng để truy cập các phương thức/attribs phụ, không phải siêu. Tôi có thể sai, nhưng hãy xem http://docs.oracle.com/cd/E11882_01/appdev.112/e11822/adobjbas.htm – tbone
có, bạn nói đúng. Các tài liệu nói TREAT chỉ có thể truy cập vào loại phụ. Nhưng làm thế nào tôi có thể sử dụng các lớp siêu? –