Pl/sql tip: How to invoke a method in a subclass that the parent class is overloaded

Source: Internet
Author: User
Tags end final sql
Skills
In C + + and Java, this is very easy to implement
C + + is: Parent class Name:: Overloaded method (parameter table), such as:
Ancestorclass::name ({arguments});
In Java, you can replace the parent class with super, such as implementing
Super.name ({arguments});

This functionality is not implemented in Oracle 9i RELEASE2,
Of course, we can use other methods to achieve this function.


Parent class object Type
Create or Replace Type parent as Object (
Rowsid Integer,
Member Procedure printattr,
Final member procedure Printattr_parent--it is best to add final to prevent subclasses from overloading this method
) not final;
/

Create or replace Type body Parent
Member Procedure Printattr is
Begin
Printattr_parent;
End;

Final member procedure printattr_parent are
Begin
super.printattr; This sentence is wrong, will throw identifier ' super.printattr ' must be declared. So to delete this sentence.
Dbms_output.put_line (' Parent-class method, rowsid:= ' | | ROWSID);
End;
End;
/


Child class object Type
Create or replace type child under parent (
overriding member procedure Printattr
) not final;
/

Create or replace type body child is
Overriding member procedure Printattr is
Begin
Dbms_output.put_line (' Subclass procedure---before calling the parent class procedure ');
--Here we want to use self.printattr, because printattr is not a procedure defined directly in a subclass
self.printattr;
Dbms_output.put_line (' Subclass procedure---After calling the parent class procedure ');
End;
End;
/


And then we'll do a test:
Declare
Vparent Parent: = parent (1);
Vchild Child: = Child (11);
Begin
Dbms_output.put_line (' Run parent process ');
vparent.printattr;
Dbms_output.put_line (' Run subclass process ');
vchild.printattr;
End


Run Result:

Running the parent class procedure
Parent class method, Rowsid:=1
Run the subclass procedure
Subclass procedure---Before calling the parent class procedure
Parent class method, rowsid:=11
After the subclass procedure---Calling the parent class procedure


Although this is a bit of a problem, the parent has several overloaded methods, and you have to add several additional methods to the parent class.
But there is no way, ' curve Save the Nation '.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.