Object-Oriented Programming Using SOM and DSOM:Understanding the Basics:Parent Class VS. Metaclass

From EDM2
Jump to: navigation, search

The notion of a parent class and a metaclass and their respective inheritance hierarchy can be confusing. Any given class in SOM has one or more parent classes and one metaclass. A metaclass has its own inheritance hierarchy that is independent of the class inheritance hierarchy. Consider the example in Figure 3.5.

SOM-DSOM-Fig-3 5.png

Figure 3.5 Parent class vs. metaclass

Here the parent class of Animal is SOMObject. This means that Animal inherits all the instance methods and the instance variables from SOMObject. An instance of Animal can invoke any of the instance methods defined in SOMObject or Animal class.

The metaclass of Animal is MetaAnimal. MetaAnimal defines the class methods for the Animal class object to perform. The class object Animal is an instance of the metaclass MetaAnimal.

Recall that SOMObject is the root of all SOM classes and SOMClass is the root of all SOM metaclasses. Thus, two independent hierarchies are formed as denoted by the solid line. The relationships between a class and its parent classes, or metaclass, are defined in the IDL. If you do not specify a parent class, the default is SOMObject. If you do not specify a metaclass, the default is SOMClass.