4. Working with Classes : Inheritance
 
Share this page                  
Inheritance
OpenROAD classes are organized into an inheritance hierarchy. With inheritance hierarchy, a class that is a child of another class is considered its subclass and a class that is the parent of another class is considered its superclass. Each subclass inherits the attributes and methods for all its superclasses.
The higher a class's position in the hierarchy, the more generalized are the characteristics and functions that it defines. Classes lower in the hierarchy describe objects with specialized characteristics that function in a specific manner. For example, the characteristics and functions defined for the FieldObject system class apply to all fields and menu items, whereas the ButtonField system class defines a very specific object.
The inheritance hierarchy is useful in avoiding redundant definition of functions and characteristics. Attributes and methods are defined at the most general level possible and inherited by all subclasses.
For example, the ButtonField system class is a subclass of ScalarField. The complete list of attributes and methods available for ButtonField includes the attributes defined for ScalarField and its superclasses (ActiveField, FormField, FieldObject, and Object) and those defined specifically for ButtonField.
Because both ButtonField objects and SliderField objects have background color, both of these system classes inherit their background color (BgColor) attribute from the same superclass, FieldObject. The BgColor attribute functions identically for both field objects, for example:
field(my_button_field).BgColor = CC_YELLOW;
field(my_slider).BgColor = CC_YELLOW;
Some classes are created for the sole purpose of high-level attribute and method definition. General classes that are used for classification only are known as abstract classes in object‑oriented programming. Examples of abstract system classes in OpenROAD include ActiveField and FieldObject.