Forming the Class Hierarchy Matrix To form the class hierarchy matrix, we use a square Boolean matrix with dimensions equal to the number of classes under consideration. Each class would correspond to both a row and a column. Inheritance relationships are denoted by putting Boolean trues in the cells of the matrix where the row class inherits from the column class and by putting Boolean falses everywhere else, including the diagonal where the row class is the same as the column class. For instance, suppose we have three classes of interest, A, B, and C, a 3x3 matrix is called for. We have found the class hierarchy matrix to aid immensely in finding transitive inheritances and detecting circular inheritances.
Transitive inheritances are superclass-subclass relationships separated by at least one generation.
For example, if C directly inherits from B and B directly inherits from A, then C inheriting from A would be considered a transitive inheritance. Circular inheritance occurs when a class simultaneously inherits from and is inherited by another class. For projects involving a handful of classes, circular inheritance could be found easily through inspection, but for large-scale object migration projects where hundreds of classes created by different programmers are involved, maintaining legitimate inheritance structures cannot be accomplished by inspection alone. Class hierarchy matrices and matrix algebra remedy the situation by providing a fast and accurate algorithm for finding classes entangled in circular inheritance structures. To use the class hierarchy matrix to find transitive inheritances and detect circular inheritances, we first form the class hierarchy matrix by inserting trues into cells where the row class inherits from the column class.