问题
I have imported a PHP source folder into Enterprise Architect. Now, I'd like to see the inheritance chain of any specific class. In other words, I'd like to see one big diagram displaying all relations of a class. Most classes are in folders separate from the parent/child class. How can I do that..?
This was my reason for installing Enterprise Architect: I get confused within a lengthy and branched inheritance chain. It would be very disappointing if such a powerful tool that recognizes all relationships could not give an overview of these relationships.
For example, I can see a class diagram in the root of one folder, illustrating aggregation. However, the aggregated classes listed are only those located in the same folder as the parent class.
Thank you in advance.
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/12584991/enterprise-architect-8-displaying-inheritance-chain-for-a-class