Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 | 

Inheritance

Description

CUBRID allows multiple inheritance, which means that a class can inherit attributes and methods from more than one superclass. However, inheritance can cause conflicts when an attribute or method of the superclass is added or deleted.

Such conflict occurs in multiple inheritance if there are attributes or methods with the same name in different superclasses. For example, if it is likely that a class inherits attributes of the same name and type from more than one superclass, you must specify the attributes to be inherited. In such a case, if the inherited superclass is deleted, a new attribute of the same name and type must be inherited from another superclass. In most cases, the database system resolves such problems automatically. However, if you don't like the way that the system resolves a problem, you can resolve it manually by using the INHERIT clause.

When attributes are inherited from more than one superclass, it is possible that their names are to be the same, while their domains are different. For example, two superclasses may have the same attribute, whose domain is a class. In this case, a subclass automatically inherits attributes with more specialized (a lower in the class hierarchy) domains. If such conflict occurs between basic data types (e.g. STRING or INTEGER) provided by the system, inheritance fails. Conflicts during inheritance and their resolutions will be covered in the Resolving Class Conflicts section.

Syntax

CREATE { CLASS | TABLE } class_name
[ {UNDER | AS SUBCLASS OF } super_class_name [ {, super_class_name }_ ] ]
[ CLASS ATTRIBUTE
( class_attr_definition_list ) ]
[ ( attr_definition | class_constraint
[ { , attr_definition | class_constraint_definition }_ ] ) ]
[ METHOD method_definition_list ] ]
[ FILE path_name_list ] ]
[ INHERIT resolution_list [ {, resolution_list }_ ] ] [ ; ]

super_class_name:
[ user_name.]classname

class_attr_definition:
attribute_name datatype [ DEFAULT value ] [ NOT NULL ]

attr_definition:
attribute_name datatype [ { SHARED [ value ] | DEFAULT value } ] [ constraints ]

constraints:
NOT NULL
UNIQUE

class_constraint_definition:
[ CONSTRAINT constraint_name ] UNIQUE
(attribute_name [{, attribute_name} ...])

method_definition:
[ CLASS ] method_name [ ( [ arg_type_list ] ) ]
[ result_type ] [ FUNCTION method_implementation_name ]

arg_type:
datatype

result_type:
datatype

resolution_list:
attr_mthd_name OF super_class_name [ AS alias ]

The following cautions must be observed during inheritance:

  • The class name must be unique in the database. A class can be created as a subclass of one or more superclass names in the database optionally. An error occurs if you create a class that inherits another class that does not exist.
  • The name of a method/attribute must be unique within a class. The name cannot contain spaces, and cannot be a reserved keyword of CUBRID. Alphabets as well as '_', '#', '%' are allowed in the class name, but the first character cannot be '_'. A class name cannot exceed 255 English letters. Class names are not case-sensitive. A class name will be saved in the system after being converted to lowercase characters.

A superclass name can begin with the user name so that the owner of the class can be easily identified.

For compatibility with relational DBMS, a TABLE keyword may be used instead of CLASS in the CREATE statement. The attribute has the same meaning as the column of a table in the relational DBMS.