10.12.2012 Views

Oracle C++ Call Interface Programmer's Guide

Oracle C++ Call Interface Programmer's Guide

Oracle C++ Call Interface Programmer's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Type Inheritance<br />

Instance substitutability refers to the ability to use an object value of a subtype in a<br />

context declared in terms of a supertype. REF substitutability refers to the ability to<br />

use a REF to a subtype in a context declared in terms of a REF to a supertype.<br />

REF type attributes are substitutable, that is, an attribute defined as REF T can hold<br />

a REF to an instance of T or any of its subtypes.<br />

Object type attributes are substitutable, that is, an attribute defined to be of (an<br />

object) type T can hold an instance of T or any of its subtypes.<br />

Collection element types are substitutable, that is, if we define a collection of<br />

elements of type T, then it can hold instances of type T and any of its subtypes. Here<br />

is an example of object attribute substitutability:<br />

CREATE TYPE Book_t AS OBJECT<br />

( title VARCHAR2(30),<br />

author Person_t /* substitutable */);<br />

Thus, a Book_t instance can be created by specifying a title string and a Person_t<br />

(or any subtype of Person_t) object:<br />

Book_t(‘My <strong>Oracle</strong> Experience’,<br />

Employee_t(12345, ‘Joe’, ‘SF’, 1111, NULL))<br />

NOT INSTANTIABLE Types and Methods<br />

A type can be declared NOT INSTANTIABLE, which means that there is no<br />

constructor (default or user defined) for the type. Thus, it will not be possible to<br />

construct instances of this type. The typical usage would be to define instantiable<br />

subtypes for such a type. Here is how this property is used:<br />

CREATE TYPE Address_t AS OBJECT(...) NOT INSTANTIABLE NOT FINAL;<br />

CREATE TYPE USAddress_t UNDER Address_t(...);<br />

CREATE TYPE IntlAddress_t UNDER Address_t(...);<br />

A method of a type can be declared to be NOT INSTANTIABLE. Declaring a method<br />

as NOT INSTANTIABLE means that the type is not providing an implementation<br />

for that method. Further, a type that contains any NOT INSTANTIABLE methods<br />

must necessarily be declared as NOT INSTANTIABLE. For example:<br />

CREATE TYPE T AS OBJECT<br />

(<br />

x NUMBER,<br />

NOT INSTANTIABLE MEMBER FUNCTION func1() RETURN NUMBER<br />

) NOT INSTANTIABLE;<br />

Object Programming 3-27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!