The code below illustrates - look specifically at what CheckAnimal()
does. Also notice the constructor hack. PL/SQL does not allow you to
call the parent constructor in your child class's constructor. In
Delphi I would code a child class constructor (and destructor)
something like this:
==
begin
-- call the parent class constructor
inherited create;
-- do the local construction stuff
..
end;
==
This is not possible in PL/SQL, and thus you need to hack it to ensure
that the parent classes constructors up the chain do their thing.
SQL> create or replace type TAnimal as Object
2 (
3 id number(20),
4
5 member procedure AnimalConstructor( self IN OUT TAnimal ),
6 constructor function TAnimal return self as result
7 ) not final;
8 /
Type created.
SQL> create or replace type body TAnimal as
2
3 member procedure AnimalConstructor( self IN OUT TAnimal ) is
4 begin
5 self.id := TO_NUMBER( TO_CHAR(sysdate,'yyyydddhh24miss')
);
6 end;
7
8 constructor function TAnimal return self as result is
9 begin
10 self.AnimalConstructor;
11 return;
12 end;
13
14 end;
15 /
Type body created.
SQL> create or replace type TMammel under TAnimal
2 (
3 cat varchar2(20),
4 subcat varchar2(20),
5
6 member procedure MammelConstructor( self IN OUT TMammel ),
7 constructor function TMammel return self as result
8 ) not final;
9 /
Type created.
SQL> create or replace type body TMammel as
2
3 member procedure MammelConstructor( self IN OUT TMammel ) is
4 begin
5 self.AnimalConstructor;
6 self.cat := 'WARMBLOODED';
7 self.subcat := 'UNKNOWN';
8 end;
9
10
11 constructor function TMammel return self as result is
12 begin
13 MammelConstructor;
14 return;
15 end;
16
17 end;
18 /
Type body created.
SQL> create or replace type TCow under TMammel
2 (
3 name varchar2(20),
4
5 member procedure CowConstructor( self IN OUT TCow ),
6 constructor function TCow return self as result,
7 member procedure Dump
8 );
9 /
Type created.
SQL> create or replace type body TCow as
2
3 member procedure CowConstructor( self IN OUT TCow ) is
4 begin
5 self.MammelConstructor;
6 self.subcat := 'BOVINE';
7 end;
8
9 constructor function TCow return self as result is
10 begin
11 self.CowConstructor;
12 return;
13 end;
14
15 member procedure Dump is
16 PS1 constant varchar2(20) := 'TCow> ';
17 begin
18 W( PS1||'id='||self.id );
19 W( PS1||'cat='||self.cat );
20 W( PS1||'subcat='||self.subcat );
21 W( PS1||'name='||self.name );
22 end;
23
24
25 end;
26 /
Type body created.
SQL> create or replace procedure CheckAnimal( uanimal TAnimal ) is
2 cow$ TCow;
3 begin
4 if uanimal is of (TCow) then
5 cow$ := TREAT(uanimal as TCow);
6 cow$.Dump;
7 end if;
8 end;
9 /
Procedure created.
SQL> declare
2 cow$ TCow;
3 begin
4 cow$ := TCow();
5 cow$.Name := 'Mina Moo';
6 CheckAnimal( cow$ );
7 end;
8 /
TCow> id=2005175075520
TCow> cat=WARMBLOODED
TCow> subcat=BOVINE
TCow> name=Mina Moo
PL/SQL procedure successfully completed.
SQL>
--
Billy
--
Billy
If I understand your setup, there's no requirment to 'deref something into a
parent class'.
Maybe, this link helps:
http://www.adp-gmbh.ch/ora/plsql/oo/example_2.html
Rene
--
Rene Nyffenegger
http://www.adp-gmbh.ch/