Managing Inheritance
Multiple-row-type tables can be useful when you want to represent objects of different types from the same relation if this relation contains both instances of a given class and instances of a subclass.
The previous example has been modified as follows:
Managing Inheritance
The employees relation can now contain objects of type Employee and objects of type Executive. Even if the class Executive inherits from the class Employee, its instances will be notified as instances of a separate class. If you want to store employees and executives in the same table, you must create a multiple row-type table. To do so:
-
Expand the class Department.
-
Expand the relation employees.
Under the employees relation, all the possible child types are displayed as inheritance relations (with a blue arrow pointing from the subtype to the parent type).
-
Select the Executive child relation and drag it onto the bottom pane.
A multiple-row-type table is created with one row for Employee objects and one row for Executive objects.
-
Select the employees relation to map the attributes of the Employee class to the row that represents employees.
-
Select the Executive child relation to map specific attributes of the Executive type to the row that represents executives.
Of course, any attribute that is common to both types can be dragged both onto the employee row and onto the executive row.
Note
Always select the right relation when you fill the cells of a row. For instance, if you have selected the Executive inheritance relation and you try to drag an attribute on the employee row, Studio will write Executive.attribute. Inheritance relations are considered as a path to access attributes of the subtype. |
The foregoing actions generate the following view specification:
subscribe origin Department:
represent IlsSwTable table:
string column[1]="name";
string column[2]="monthCost";
string column[3]="hireDate";
string column[4]="title";
...
propagate employees;
propagate executives;
subscribe Employee:
represent IlsSwRow employeeRow:
mandatory Ref<IlsSwTable> table=view.origin->table;
string column[1]=name;
int column[2]=monthCost;
int column[3]=hireDate;
subscribe Executive:
represent IlsSwRow executiveRow:
mandatory Ref<IlsSwTable> table=view.origin->table;
string column[1]=name;
int column[2]=monthCost;
int column[3]=hireDate;
string column[4]=title;
In this view specification, title is an attribute of the Executive class. This column is left blank for instances that are not of the type Executive.
You can find more information about the way inheritance is handled within the Server/Views mapping in Managing Inheritance Using Multiple-Row-Type Tables.