What is inheritance?
Inheritance enables you to share attributes between objects such that a subclass inherits attributes from its parent class.
Inheritance is the process that allows a type or a table to acquire the properties of another type or table. The type or table that inherits the properties is called the subtype or subtable. The type or table whose properties are inherited is called the supertype or supertable. Inheritance allows for incremental modification so that a type or table can inherit a general set of properties and add specific properties. You can use inheritance to make modifications only to the extent that the modifications do not alter the inherited supertypes or supertables.
Type inheritance
Type inheritance applies to named row types only. You can use inheritance to a group named row types into a type hierarchy in which each subtype inherits the representation (data fields) and the behaviour of the supertype under which it is defined. A type hierarchy provides the following advantages:
- It encourages modular implementation of your data model.
- It ensures consistent reuse of schema components.
- It ensures that no data fields are accidentally left out.
Table inheritance
Only tables that are defined on named row types support table inheritance. Table inheritance is the property that allows a table to inherit the behaviour (constraints, storage options, triggers) from the supertable above it in the table hierarchy. A table hierarchy is a relationship that you can define among tables in which subtables inherit the behavior of supertables. A table inheritance provides the following advantages:
- It encourages modular implementation of your data model.
- It ensures consistent reuse of schema components.
- It allows you to construct queries whose scope can be some or all of the tables in the table hierarchy.
In a table hierarchy, a subtable automatically inherits the following properties from its supertable:
All constraint definitions (primary key, unique, and referential constraints)
- Storage option
- All triggers
- Indexes
- Access method