Enterprise Architect 8 > Displaying Inheritance Chain for a Class

主宰稳场 提交于 2019-12-04 19:01:36

This answer applies to EA 9.3. I don't have an old EA 8 lying around but EA is eminently backwards-compatible, so you should upgrade in any case.

There are a couple of ways to follow inheritance chains in EA.

Method 1: add classes to the same diagram.

In a diagram containing the root class of your inheritance hierarchy, right-click the root class and select Add - Related Elements. In the "Insert Related Elements" dialog, select the length of chain ("levels") you want, up to a maximum of 5. Specify "link type" Generalization. You can leave the other options as they are, or play around with them if you like.

This will cause EA to add those classes to the diagram which inherit from the root class in up to 5 steps/levels. You don't have to start from a root class; the option "link direction" in the dialog controls whether relationships should be followed in one or both directions.

You can use this same function to add classes related through other relationships, such as aggregations.

Method 2: Use the Traceability window.

In the main menu, select View - Traceability. This opens the Traceability window, which is a tree view with the currenty selected element at the top, and nodes for all related elements in a hierarchy.

Select the root class and violà, all its inheriting classes are shown as child nodes in the Traceability window, and you can expand them in turn to follow the chains further.

Method 1 puts the information in diagrams, where it is kept and needs to be updated. Method 2 is dynamic and more usefu when you need to check a specific relationship chain.

The relationships in a diagram are automatically updated if the underlying model changes, so if for instance you change the code and reimport it, this will be reflected in the diagram. To be on the safe side, always work with manually created diagrams in a separate package from the source package.

Am not sure if there is existing solution but is something you can easily implement using ReflectionClass and Google Graph

Example

class A {
}
class B extends A {
}
class C extends B {
}
class D extends C {
}
class E extends D {
}
class F extends E {
}

function getPath($className) {
    $class = new ReflectionClass($className);
    $name = $class->getParentClass();
    if ($name) {
        echo $class->getName(), " extends ";
        getPath($name->getName());
    } else {
        echo $class->getName();
    }
}

getPath("C");
getPath("F");

Output

C extends B extends A
F extends E extends D extends C extends B extends A
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!