Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

Superclass Conflict

Adding a Superclass

The INHERIT clause of the ALTER CLASS statement is optional, but must be used when a conflict occurs due to class changes. You can specify more than one resolutions after the INHERIT clause.

superclass_name specifies the name of the superclass that has the new attribute or method to inherit when a conflict occurs. attr_mthd_name specifies the name of the attribute or method to inherit. You can use the alias clause when you need to change the name of the attribute or method to inherit.

The following example creates the soccer_stadium class by inheriting the event and stadium classes in the olympic database of demodb. Because both event and stadium classes have the name and code attributes, you must specify the attributes to inherit using the INHERIT clause.

CREATE CLASS soccer_stadium UNDER event, stadium
INHERIT name OF stadium, code OF stadium;

When the two superclasses (event and stadium) have the name attribute, if the soccer_stadium class needs to inherit both attributes, it can inherit the name unchanged from the stadium class and the name changed from the event class by using the alias clause of the INHERIT.

The following is an example in which the name attribute of the stadium class is inherited as it is, and that of the event class is inherited as the 'purpose' alias.

ALTER CLASS soccer_stadium
INHERIT name OF event AS purpose;

Deleting a Superclass

A name conflict may occur again if a superclass that explicitly inherited an attribute or method is dropped by using the INHERIT. In this case, you must specify the attribute or method to be explicitly inherited when dropping the superclass.

The following is an example of creating the seoul_1988_soccer class by inheriting game, participant and stadium classes from demodb, and deleting the participant class from the superclass. Because nation_code and host_year are explicitly inherited from the participant class, you must resolve their name conflicts before deleting it from the superclass. However, host_year does not need to be specified explicitly because it exists only in the game class.

CREATE CLASS seoul_1988_soccer UNDER game, participant, stadium
INHERIT nation_code OF participant, host_year OF participant;
ALTER CLASS seoul_1988_soccer
INHERIT nation_code OF stadium;

Compatible Domains

When an attribute conflict occurs among two or more superclasses, the statement resolving the conflict is not possible only if all attributes have compatible domains.

For example, the class that inherits a superclass with the phone attribute of integer type cannot have another superclass with the phone attribute of string type. If the types of the phone attributes of the two superclasses are both String or Integer, you can add a new superclass by resolving the conflict with the INHERIT clause.

Compatibility is checked when inheriting an attribute with the same name, but with the different domain. In this case, the attribute that has a lower class in the class inheritance hierarchy as the domain is automatically inherited. If the domains of the attributes to inherit are compatible, the conflict must be resolved in the class where an inheritance relationship is defined.