Call base type constructor [message #419209] |
Thu, 20 August 2009 07:10 |
Yurkech
Messages: 9 Registered: March 2009
|
Junior Member |
|
|
create or replace
type test1 authid current_user as object
(
a1 varchar2(255),
constructor function test1(a1 varchar2) return self as result
) not final;
create or replace
type body test1 is
constructor function test1(a1 varchar2) return self as result
as
begin
self.a1 := a1;
dbms_output.put_line('Test1 ' || self.a1);
return;
end;
end;
/
create or replace
type test2 under test1
(
constructor function test2(a1 varchar2) return self as result
) not final;
create or replace
type body test2 is
constructor function test2(a1 varchar2) return self as result
as
begin
self.a1 := a1;
dbms_output.put_line('Test2 ' || self.a1);
return;
end;
end;
/
declare
t2 test2;
begin
t2 := test2('123');
end;
/
Output of this example is:
Test2 123
The logic placed in test1 constructor(base type) was lost cause of compiler of pl/sql didn't call base type constructor.
How can I implicitly call this constructor?
Something like this!?:
create or replace
type body test2 is
constructor function test2(a1 varchar2) return self as result
as
begin
super(a1);
dbms_output.put_line('Test2 ' || self.a1);
return;
end;
end;
I couldn't find any example. Help, please!
Thanks!
|
|
|
Re: Call base type constructor [message #419215 is a reply to message #419209] |
Thu, 20 August 2009 08:15 |
|
Michel Cadot
Messages: 68718 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Oracle version 10.3 does not exist.
If it said in Database Application Developer's Guide - Object-Relational Features, Overloading and Hiding Constructors
Quote: | User-defined constructors are not inherited, so a user-defined constructor defined in a supertype cannot be hidden in a subtype. However, a user-defined constructor does hide, and thus supersede, the attribute-value constructor for its type if the signature of the user-defined constructor exactly matches the signature of the attribute-value constructor...
|
Regards
Michel
From your previous topic:
Michel Cadot wrote on Tue, 10 March 2009 17:15 | Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter), use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version (4 decimals).
Regards
Michel
|
By the way did you find the solution for this previous topic?
|
|
|
|
|
Re: Call base type constructor [message #419222 is a reply to message #419209] |
Thu, 20 August 2009 09:35 |
Yurkech
Messages: 9 Registered: March 2009
|
Junior Member |
|
|
Can you give me some advice, how can I separate logic between base and derived types in this situation. Its very uncomfortable and inflexible to copy code every time.
How can I do that each type in hierarchy make only his part of work.
I think that problems is the same with methods (members)...
I have hierarchy of type. Each type have to initialise some variables required for working. And It will be great that every new derived type haven't to redo initialisation which have been done in his bases types.
Thanks for your attention!
|
|
|